[Snort-devel] a note on code cleanliness

Todd Lewis tlewis at ...255...
Fri Apr 27 20:09:45 EDT 2001


I don't know if any of the other developers have ever noticed, but any
code that I submit for public consumption is first compiled with full
warnings enabled and the ansi and pedantic flags to gcc, like this: 

WARNINGS= -Wall -W -Wshadow -Wpointer-arith -Wbad-function-cast \
-Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wstrict-prototypes \
-Wmissing-prototypes
CFLAGS=-ansi -pedantic -$(WARNINGS)

If the compiler is not completely satisfied that my code is clean with
these settings, then I either fix the code about which the compiler
complains, or I satisfy myself that I know what I am doing and can live
with the compiler being unhappy, in which case I put a comment in the code
explaining what is going on for future investigators to read.

Take a look at my smodule patch and the accompanying tests that I
posted several days ago for an example of this style in practice.
Both smodule.c and the accompanying tests compile with the above flags
with nary a complaint out of gcc.

Whenever I am tasked with debugging code, the first thing that I try to do
is make the code kosher in the eyes of the compiler.  Often, the compiler
tells you exactly what the problem is, if only you bother to ask it,
and once you make your code clean, debugging further problems is much
easier, because all of the easily-fixed bugs already have been removed.

Compiling snort with the "-ansi" flag to gcc appears to be impossible, and
"-pedantic" appears to break at least one preprocessor.  With the code in
this state, my normal approach to debugging is somewhat stymied.

I am assuming that, at this late date, a wholesale scrubbing of the
codebase to address these issues would not be welcome, but I could be
wrong, which is why I bring it up.

Making the code base clean in the eyes of the compiler is towards the
top of my list of things that I would like to see come out of the 2.0
development effort.  It will eliminate a lot of mysterious bugs that,
odds are, we don't even notice right now.

--
Todd Lewis
tlewis at ...255...





More information about the Snort-devel mailing list