http://man7.org/linux/man-pages/man3/strncpy.3.html I see: strncpy(buf, str, buflen - 1); if (buflen > 0) buf[buflen - 1]= '\0'; I expected: if (buflen > 0) { strncpy(buf, str, buflen - 1); buf[buflen - 1]= '\0'; } (I expected `buflen` to be checked against `0` BEFORE calling `strncpy()`, not AFTER) Robin Kuzmin kuzmin.robin@xxxxxxxxx