Page 1 of 1

Bug in the kernel

Posted: Thu Mar 27, 2008 11:54 pm
by Andyhhp
Hi,

in string.cpp of the 'lib' part of the kernel, you have the following function is defined

Code: Select all

//! copies string s2 to s1
char *strcpy(char *s1, const char *s2)
{
    char *s1_p = s1;
    while (*s1++ = *s2++);
    return s1_p;
}


Surely you need either a length parameter or a test for a null terminator otherwise you will write your way to the end of memory.

My suggesting would be:

Code: Select all

//! copies string s2 to s1
char *strcpy(char *s1, const char *s2)
{
    char *s1_p = s1;
    while (*s1)
        *s1++ = *s2++;
    return s1_p;
}


Andrew

Posted: Fri Mar 28, 2008 5:36 am
by Mike
Hey,

The routine within the series does work (It has been tested). Its basically the same thing your routine does, but written in a more condensed form. (We test for the null terminator inside of the while loop.)

It can be written cleaner, though. Thanks for letting us know!