Quantcast
Channel: User vesperto - Stack Overflow
Viewing all articles
Browse latest Browse all 44

Answer by vesperto for Program segfaulting in release version only

$
0
0

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.


Viewing all articles
Browse latest Browse all 44

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>