[Ksummit-discuss] [MAINTAINERS SUMMIT] API replacement/deprecation

Theodore Y. Ts'o tytso at mit.edu
Sat Sep 8 15:19:53 UTC 2018


On Sat, Sep 08, 2018 at 10:15:01AM +0200, Geert Uytterhoeven wrote:
> Why the memset()? strncpy() pads the destination with zeroes, so it
> is not needed. This is basically the major reason to use strncpy().

I had completely forgotten about that!  I've always focused on when
strncpy would stop copying, and the lack of NUL termination in some
cases; not that it automatically zero'ed the padding.  Since I tend to
always memset the entire structure to be zero, I started assuming that
I couldn't count on strncpy to NUL pad.

Perhaps all we need to do is to rename strncpy to make it clear when
it's appropriate it, and when it simply is not.


> >         strncpy(src, dest, size);
> 
> Oh, you're copying in the wrong direction ;-)

Yeah, oops.  What I get for typing too quickly.  :-)

      	     	    	    	   - Ted


More information about the Ksummit-discuss mailing list