Re:

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

 



On Mon, Jun 21, 2010 at 11:05 PM, bill o gallmeister
<bgallmeister@xxxxxxxxx> wrote:
> I believe that's the correct result for a NULL-terminated string of length 1.

And I agree.

Thanks,

Michael


> On 06/21/2010 01:30 PM, Bob Eggers wrote:
>> I noticed an error in and example on the man page for strncpy(). The page is http://www.kernel.org/doc/man-pages/online/pages/man3/strncpy.3.html
>>
>> The error is in the section, "NOTES", specifically in the code example after the text:
>>
>>       If there is no terminating null byte in the first n characters of src,
>>        strncpy() produces an unterminated string in dest.  Programmers often prevent
>>        this mistake by forcing termination as follows:
>>
>>            strncpy(buf, str, n);
>>            if (n > 0)
>>                buf[n - 1]= '\0';
>>
>> Substituting 1 for n and "123" for str, this would equate to:
>>
>>            strncpy(buf, "123", 1);  // buf is now "1"
>>            if (1 > 0)
>>                buf[1 - 1]= '\0';                // buf is now ""
>>
>> Bob Eggers--
>> To unsubscribe from this list: send the line "unsubscribe linux-man" in
>> the body of a message to majordomo@xxxxxxxxxxxxxxx
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
>
>
> --
> Bill O. Gallmeister
> bgallmeister@xxxxxxxxx
> http://geekwhisperer.blogspot.com
>



-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Author of "The Linux Programming Interface" http://blog.man7.org/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[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