On Thu, 25 Oct 2018 at 23:56, Robin Kuzmin <kuzmin.robin@xxxxxxxxx> wrote: > > 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) Why? -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/