public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Erik Andersen <andersen@codepoet.org>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: Paul P Komkoff Jr <i@stingr.net>, linux-kernel@vger.kernel.org
Subject: Re: [RFC] Some useless cleanup
Date: Thu, 9 May 2002 16:23:58 -0600	[thread overview]
Message-ID: <20020509222358.GB8651@codepoet.org> (raw)
In-Reply-To: <20020509102841.GA1125@stingr.net> <20020509223650.2d7a9f6a.rusty@rustcorp.com.au>

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);
}

 -Erik

--
Erik B. Andersen             http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--

  reply	other threads:[~2002-05-09 22:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-09 10:28 [RFC] Some useless cleanup Paul P Komkoff Jr
2002-05-09 12:36 ` Rusty Russell
2002-05-09 22:23   ` Erik Andersen [this message]
2002-05-10  8:20     ` Bernd Petrovitsch
2002-05-10 11:42     ` Oliver Xymoron
2002-05-12 12:09     ` Rusty Russell
2002-05-10  9:44   ` Paul P Komkoff Jr
2002-05-09 15:09 ` Denis Vlasenko
2002-05-09 11:33   ` Paul P Komkoff Jr

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020509222358.GB8651@codepoet.org \
    --to=andersen@codepoet.org \
    --cc=i@stingr.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox