svn commit: trunk/busybox/util-linux

Rich Felker dalias at aerifal.cx
Wed Sep 20 17:48:19 UTC 2006


On Wed, Sep 20, 2006 at 04:05:43PM +0200, Denis Vlasenko wrote:
> > > Okay, let's say you do
> > > 
> > > #define linenumber 0
> > > 
> > > What will happen if somebody, somewhere in the jungle of included
> > > header files, already used "linenumber" as a name for something?
> > 
> > In an applet?  The new #define stomps the earlier one for any lines occurring 
> > later in the program.
> 
> No, not in applet. "linenumber" can be declared in a library header
> (libc or any other external library a programs compiles against)
> as a global variable.

No, I alread debunked this nonsense. There is a VERY TIGHT restriction
on what can be used in the system libc headers. The name "linenumber"
absolutely cannot be used here because it's reserved for the
application to use in any way the author sees fit, INCLUDING #define!

> Just like FILE *stdout.

No, just the opposite of FILE and stdout. These names are reserved as
part of the implementation and may not be used by the application
except in files that (1) do not include stdio.h and (2) only use the
name stdio for non-extern.

> > > Say, putchar(), which is usually a macro, will expand to
> > > ....; linenumber = 0; .... and you will get "invalid lvalue
> > > in assignment". Not very easy to figure out.
> > 
> > And you either should know what you changed recently or you should be able to 
> > track it down to a specific svn version.  We've done this before.
> 
> Yes, it's debuggable. But it should be trivially debuggable,
> the same way when you accidentally declare
> 
> int syslog; // collides with function declaration

This is not necessarily debuggable..

> > > If putchar will expand to ....; something = linenuber;....,
> > > you get NO ERROR. You get nasty bug.
> > 
> > You get a behavior change, and you track it down.  I've tracked down much 
> > worse problems than this.
> 
> What if it is on error path? What if it triggers once in a year?

It doesn't happen at all because putchar cannot use the name
linenumber. Similarly in your own macros you should use proper local
names that do not clash with the caller's namespace.

> > And where did linenumber get declared in putchar, anyway?
> > Wouldn't "int 0;" cause the compiler to throw up?
> 
> It was a global variable declared and parsed somewhere up there
> in #include <something.h> from libc, way before gcc had a chance
> to see "#define linenumber 0"

LMAO!

Rich




More information about the busybox mailing list