Hot Door CORE Forum

Full Version: string functions may crash some Mac builds
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is not a bug report, just passing along an observation that may help others in the future.

I wrote some string formatting functions based on the utilities in CORE's ToolSample project, but did more extensive parsing of the string to work with multiple values and user ruler units. Using CORE 0.8.0 it worked perfectly under Windows and in Mac AI 25 and 26, but crashed in Mac AI 23 and 24, but only crashed in the release versions. It seems weird that the debug builds ran fine in AI 23 and 24! What's really weird is that if I used alerts::message() to report the values of variables at multiple points, it seemed to slow things down enough that AI 23-24 release worked then, too.

I used simple functions such as these to parse text, not necessarily in this order:

     int scanResult = sscanf(str.c_str(), "%lf%[a-z]%lf", &n, s1, &n2);
     std::size_t charPos = str.find_first_not_of("-.0123456789 ");
     std::string str2 = str.substr(charPos,std::string::npos);
     str.resize(charPos);


The problem is that the length of str somehow became set to 0, even though it contained text, so substr() got an out-of-bounds error. Could these standard C functions jump to the next line before the previous one finished?

Anyway, my workaround was to just not use sscanf() in this formatting function. I hope this can be helpful to others.