lkml.org 
[lkml]   [2003]   [Apr]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [TRIVIAL] kstrdup

On Fri, 18 Apr 2003, Jeff Garzik wrote:
> Linus Torvalds wrote:
> > On Fri, 18 Apr 2003, Jeff Garzik wrote:
> >
> >>You should save the strlen result to a temp var, and then s/strcpy/memcpy/
> >
> > No, you should just not do this. I don't see the point.
>
> strcpy has a test for each byte of its contents, and memcpy doesn't.
> Why search 's' for NULL twice?

No, my point is that kstrdup() _itself_ just shouldn't be done. I don't
see it as being worthy of kernel support. Most of the kernel string data
structures are NOT random zero-ended strings anyway: they are either
strictly limited in some ways ("ends in '\0', but limited to PATH_MAX), or
they are explicitly sized ("struct qstr").

I don't much personally like C strings. Explicit lengths tend to have a
lot of advantages, and while a lot of the standard C infrastructure is for
zero-ended strings, they do end up being even worse in the kernel than in
user space (think buffer overflows and limited allocations in general).

Linus

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

\
 
 \ /
  Last update: 2005-03-22 13:34    [W:0.039 / U:0.064 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site