[linux-elitists] Stupid C tricks

Jason Spence jspence@lightconsulting.com
Fri Aug 27 19:29:38 PDT 2004

On Fri, Aug 27, 2004 at 09:16:40PM -0500, Tilghman Lesher wrote: 
> On Friday 27 August 2004 20:46, Jason Spence wrote:
> > Something that's been bugging me for a while was the inability to
> > have an error reporting macro that automatically outputted the
> > filename and line number of the call to the macro, as well as take
> > variable arguments in printf(3) format so the programmer could
> > provide some information on the state of the program at the time
> > the error occured.
> >
> > I figured it out a way to get both last month; please let me know
> > what you think.
> >
> > http://lightconsulting.com/~thalakan/drop/ngdebug.c
> I'm missing something.  Why aren't you just using __FILE__, __LINE__,

More typing, no centralization of the output format, and you have to
sync more stuff in the format string with the arguments (especially
bad for compilers like MS C w/o prefast that don't support something
like GCC's __attribute((format(printf))) ).  It's been my experience
that the more work programmers have to do to report errors, the less
reports you get, and when they do report problems, the reports are
lower in quality.  In addition, reporting mechanisms that don't easily
support variable arguments and/or require manual buffer construction
to report the error cause errors like this:

FATAL ERROR: cannot open file.


And, of course, the user is on the other side of the dialog cursing
the programmer to high heaven, screaming things like "WHAT FILE?!  WHY
REASON WAS?!"  Variable argument support in the error reporting
routines eliminate this problem.

In addition, manually constructing the buffer to report errors
involving user supplied data is a good way to get a one-way ticket to
exploit city, especially if your programmers lack secure coding

 - Jason                                                 Last known location: 

"It's not Camelot, but it's not Cleveland, either."
		-- Kevin White, mayor of Boston

More information about the linux-elitists mailing list