They told me if I used the n version I'd be safe. They told me the risks were tiny. That all we had to do was practice safe counting.
They told me that... ˚sob˚ but they were wrong.
They told me that... ˚sob˚ but they were wrong.
Programs (often) handle text. Apparently, that pretty much means you're fucked. So what is a reasonable way to write such programs?
Edited to add:
Apparently there is this: http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/cordh...
The problem isn't necessarily the functions themselves, it's coders who make assumptions that don't pan out to be true.
struct string {
char *str;
unsigned length;
} "%.*s"
or possibly even "%*.*s"
if you want it space padded. In principle you can bound your space usage and avoid an snprintf with such constructs; in practice, it's probably better to still use snprintf (if you're using standard-library string functions at all).