Linux-kernel mailing list archive 1999-22,: Re: Minor bug in lib/string.c

# Re: Minor bug in lib/string.c

Brad Proctor (fredlie@sprynet.com)
Sat, 29 May 1999 00:03:06 -0400

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Keith Owens: "Re: [2.2.9] performance problem on 100MBit network"
- Previous message: Vilain, Sam: "RE: 2.3.x wish list?"

Y2K wrote:
>
> On Thu, 27 May 1999, Brad Proctor wrote:
> > I didn't know were else to send this. The Linux docs say if I'm total
> > clueless, send it here. :)
> > I found a minor bug in lib/string.c, in the strncpy() function. These
> > two lines need to be added after the first while loop.
> > while(count--)
> > *dest++ = '\0';
> > ANSI says strncpy() needs to have the destination string null padded
> > to 'count' bytes if the source string has ended.
> That sounds not right. Can you name the document and section?

ISO C Standard 9899:1990
Section 7.11.2.4

Synopsis

#include <string.h>
char *strncpy(char *s1, const char *s2, size_t n);

[snip]
"If the array pointed to by s2 is a string that is shorter than n
characters, null characters are appended to the copy in the array
pointed to by s1, until n characters in all have been written."
> You mean in the kernel source. not the libc. Perhaps they should have
> called it kstrncpy 'cause it's not visible to user-space and ansi doesn't
> apply there anyway.

I guess it doesn't really matter then, unless someone writing kernel
code expects it to behave this way, which is doubtful.

Brad Proctor

    --
    "Doc, you gotta help us, we've tried nothing
    and we're all out of ideas!" -- Ned Flanders mother

    Email: <fredie@sprynet.com>
    Home Page: "http://members.xoom.com/fredlie/"

    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.rutgers.edu
    Please read the FAQ at http://www.tux.org/lkml/

- Next message: Keith Owens: "Re: [2.2.9] performance problem on 100MBit network"
- Previous message: Vilain, Sam: "RE: 2.3.x wish list?"