Re: man3/strncpy.3.html

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux