-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Description
Probably a bug in MSVC compiler, but entering this issue here anyway since using Poco's trimInPlace on an empty string crashes when built for windows:
String.h, trimInPlace does this:
int first = 0;
int last = int(str.size()) - 1;
while (first <= last && Ascii::isSpace(str[first])) ++first;
while (last >= first && Ascii::isSpace(str[last])) --last;
str.resize(last + 1);
str.erase(0, first);
This code works fine on macOS and linux, but fails with Visual Studio Express 2017 (in multiple versions, including the latest v15.9.17).
If the string is empty, then the value of last is -1 and the call to str.resize(last+1) will crash in microsoft's xstring void resize(_CRT_GUARDOVERFLOW const size_type _Newsize, const _Elem _Ch = _Elem()). the value of _Newsize is reported in the debugger as 4294967295
changing the code as follows works around it:
int newSize = last + 1;
str.resize(newSize);
i guess it's an issue in MSVC, somehow casting last to the argument type before adding 1?
Reactions are currently unavailable