Re: Usage of strncpy in the kernel

Mouse <[email protected]>
Newsgroups gmane.os.netbsd.devel.kernel
Message-ID <[email protected]>
> I stumbled across a few usages of strncpy in the kernel [...]

>> strlcpy(name, "... preferred name ...", sizeof(sc->sc_sensor.desc));
[...]
>> strlcpy(sc->sc_sensor.desc, name, sizeof(sc->sc_sensor.desc));

Um, strlcpy != strncpy.  Are you counting strlcpy as a variant of
strncpy for purposes of this suggestion?

> These code snippets made me wonder whether strncpy should be banned
> from kernel code, in order to force developers to think about
> properly handling character arrays and strings.

But what would you use, then, to copy a string?  I have trouble
imagining that strcpy would be any better.  bcopy/memcpy?  I suspect
you'd find that the problem is not the routine used; the problem is, as
you imply, lack of thought, but that switching routines will not
alleviate that - it'll just result in the problematic coders writing
what they think is a correct copy using whatever you pick instead while
still getting it wrong one way or another.

/~\ The ASCII				  Mouse
\ / Ribbon Campaign
 X  Against HTML		[email protected]
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.