4 ms·
It can happen easily if you don't pay attention with only the standard library. const char *hello = "Hello World !", *world = "World"; char *tmpStr = s
by _ache_ 4y ago
It can happen easily if you don't pay attention with only the standard library.
const char *hello = "Hello World !", *world = "World";
char *tmpStr = strstr(hello, world); // IMPLICITE cast from const to non const
if(tmpStr) {
*tmpStr = 0; // Oupss
}
C is hard.
- synergy20 4y agoso how to safely use strstr then? this is truly a bug hard to find, yet another caveat. not sure if fuzz testing can help here. I wonder how many implicit-const-to-non-cost API are in ANSI C and Posix C