▲ | wahern a day ago | |||||||
> I always have understood that snprintf does not write a null character when the produced string is longer than the given size. snprintf always null-terminates when the buffer length is greater than 0 and there's no error. That is, if snprintf returns >= 0 and the buffer length is > 0, the output is null-terminated. This should be clear from your local snprintf(3) man page (e.g. https://man.openbsd.org/snprintf), but also see the C23 standard (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf) and POSIX (https://pubs.opengroup.org/onlinepubs/9799919799/). | ||||||||
▲ | fjfaase 11 hours ago | parent [-] | |||||||
You are right. I verified this myself. I do not know where I got this wrong. Maybe this was different in earlier implementations. | ||||||||
|