[BusyBox] save 22 binary bytes

Aaron Lehmann aaronl at vitelus.com
Wed May 16 18:10:18 UTC 2001


On Wed, May 16, 2001 at 04:46:24PM -0700, Larry Doolittle wrote:
> replaces a 4-argument function call with a 3-argument one.  But in
> 
> > -		snprintf(console, sizeof(console) - 1, "/dev/null");
> > +		strncpy(console, "/dev/null", sizeof(console) - 1);
> 
> they both have 3 arguments.

Yes, I noticed this. The point is that strncpy is cleaner and more
appropriate for these situations.

> You'd have to look at the assembly output to see why no
> space was saved.

I did so, and found that GCC (2.95.3 AND 3.0pre, with -Os) was
inserting an:

    addl $-4,%esp

...before the three pushes. So one of the pushes (the %s) was just
getting replaced with that add instruction. Weird.

> Also, your changes should use safe_strncpy instead of strncpy.

strncpy should be as "safe" as snprintf was, unless there is some
preexisting bug. But in principle, this probably a good idea.





More information about the busybox mailing list