tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Usage of strncpy in the kernel
> 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 mouse%rodents-montreal.org@localhost
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B
Home |
Main Index |
Thread Index |
Old Index