uscxml
uscxml copied to clipboard
[MSVC 2015] All Ctype functions like 'isspace' should be changed to be safe
Example of the problem
ISWHITESPACE function in String.cpp cause Debug Assertion if non-latin symbol is used
<scxml datamodel="ecmascript" initial="StateShape3" name="ScxmlShape1" version="1.0" xmlns="http://www.w3.org/2005/07/scxml">
<state id="StateShape3" initial="тест">
<transition event="Quit" target="FinalShape1"/>
<state id="StateShape2">
<transition cond="! (_event.data=="привет")" event="b" target="тест"/>
</state>
<state id="тест">
<transition cond="_event.data=="привет"" event="b" target="StateShape2"/>
</state>
</state>
<final id="FinalShape1"/>
</scxml>
The next state machine source code cause Debug Assertion Expression: c>=-1 && c<=255 because cyrillic symbols has negative char values
The problem is in macro ISWHITESPACE from String.cpp
#define ISWHITESPACE(char) (isspace(char))

Solution
- Wrap every ctype function with macro like
#define ISWHITESPACE(symbol) (isspace(static_cast<unsigned char>(symbol)))
- Use intermediate safe function like
template<int (&F)(int)>
int safe_ctype(unsigned char c) { return F(c); }
//...
char c = CHAR_MIN;
bool b = safe_ctype<isupper>(c); // No UB.