Skip to content
Permalink
Browse files

Fix #1039: Crash for incorrect usage of "ColumnHeader" CEGUI property

  • Loading branch information...
botder committed Aug 3, 2019
1 parent 9728a27 commit bc649fb5c89cb2358c8cafad699005923cd5377f
Showing with 67 additions and 9 deletions.
  1. +67 −9 vendor/cegui-0.4.0-custom/src/elements/CEGUIMultiColumnListProperties.cpp
@@ -278,19 +278,77 @@ String ColumnHeader::get(const PropertyReceiver* receiver) const

void ColumnHeader::set(PropertyReceiver* receiver, const String& value)
{
// extract data from the value string
// Format: "text:[caption] width:[float] id:[uint]"
// Note: Components may appear in any order
String caption, width("0.33"), id("0");

size_t wstart = value.find("width:");
size_t idstart = value.find("id:");
// Extract data from the value string
size_t idstart = value.rfind("id:");
size_t wstart = value.rfind("width:");
size_t capstart = value.find("text:");

String caption(value.substr(0, wstart));
caption = caption.substr(caption.find_first_of(":") + 1);
if (capstart != String::npos)
{
capstart = value.find_first_of(":", capstart) + 1;

if (idstart == String::npos) // Missing 'id' component
{
if (wstart == String::npos || capstart > wstart)
{
// Missing 'width' component or caption comes after 'width' component
caption = value.substr(capstart);
}
else
{
// Caption is before the 'width' component
caption = value.substr(capstart, wstart - capstart);
}
}
else
{
if (wstart == String::npos) // Missing 'width' component
{
if (capstart > idstart)
{
// Caption is after the 'id' component
caption = value.substr(capstart);
}
else
{
// Caption is before the 'id' component
caption = value.substr(capstart, idstart - capstart);
}
}
else
{
if (capstart < wstart && capstart < idstart)
{
// Caption is before the 'id' and 'width' component ([caption][id/width])
caption = value.substr(capstart, std::min<size_t>(idstart, wstart) - capstart);
}
else if (capstart > wstart && capstart > idstart)
{
// Caption is after 'width' and 'id' component ([id/width][caption])
caption = value.substr(capstart);
}
else
{
// Caption is between the 'id' and 'width' components ([id or width][caption][[id or width])
caption = value.substr(capstart, std::max<size_t>(idstart, wstart) - capstart);
}
}
}
}

String width(value.substr(wstart, idstart));
width = width.substr(width.find_first_of(":") + 1);
if (wstart != String::npos)
{
width = value.substr(value.find_first_of(":", wstart) + 1);
}

String id(value.substr(idstart));
id = id.substr(id.find_first_of(":") + 1);
if (idstart != String::npos)
{
id = value.substr(value.find_first_of(":", idstart) + 1);
}

static_cast<MultiColumnList*>(receiver)->addColumn(
caption, PropertyHelper::stringToUint(id), PropertyHelper::stringToFloat(width));

1 comment on commit bc649fb

@botder

This comment has been minimized.

Copy link
Member Author

commented on bc649fb Aug 3, 2019

Please sign in to comment.
You can’t perform that action at this time.