Well, as it turns out, the original text (not "Some text"
) took 19 chars plus the %d
, which is "always" one digit. Even so, that's 20 chars in a char aCharArr[20]
, producing a char array that is not \0
-terminated.
Increasing the size of aCharArr
(to the next multiple of 8 but that's just me) fixed it and using snprintf
instead gave me peace of mind.
char aCharArr[24]; memset(aCharArr, '\0', sizeof(aCharArr));sprintf(aCharArr, "Actual str orig len%d", anInt);
Compiling in debug with -O2
as is used in release was also helpful, although the available information was enough.