lkml.org 
[lkml]   [2002]   [May]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC] Some useless cleanup
On Thu, 9 May 2002, Erik Andersen wrote:

> On Thu May 09, 2002 at 10:36:50PM +1000, Rusty Russell wrote:
> > Um, why not simply:
> >
> > static inline void set_name(struct task_struct *tsk, const char *name)
> > {
> > /* comm is always nul-terminated already */
> > strncpy(tsk->comm, name, sizeof(tsk->comm)-1);
> > }
> >
> > Your implementation using snprintf is (wasteful and) dangerous,
> > Rusty.
>
> And both implementations suffer from the fact that if tsk->comm
> were to change from a fixed length array to a char*, allowing
> arbitrarily sized names, you would end up copying very little
> indeed. :) What not something more general like:
>
> char * safe_strncpy(char *dst, const char *src, size_t size)
> {
> dst[size-1] = '\0';
> strncpy(dst, src, size-1);
> }

If we're gonna do that, we might as well adopt OpenBSD-style strlcpy and
strlcat:

http://www.courtesan.com/todd/papers/strlcpy.html

--
"Love the dolphins," she advised him. "Write by W.A.S.T.E.."

-
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:26    [W:0.457 / U:0.040 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site