-
-
Notifications
You must be signed in to change notification settings - Fork 54
drill.c -- unsafe macros are bad #220
Copy link
Copy link
Closed
Description
See SEI CERT C Coding Standard PRE10-C and PRE00-C.
In particular, the dprintf() macro was dangerously using if without corresponding else. Oh, and it was also redefining a common function (which was defined by the headers in used in the file ... ouch!) ... with different parameters. Bad, bad, bad....
C11 tried to support variadic macros, but failed to do so fully as passing zero-parameters would fail to compile. Thus, for printf() style macros (variadic), use the dual-parenthesis trick.
Here's an example of the bug that occur with the old macro for dprintf():
// Ensure number format is set to FMT_USER (and warn if not true).
if (state->number_format == FMT_USER)
dprintf("Some debugging information here.")
else
state->number_format = FMT_USER;The above code has a bug ... it doesn't actually ever set the number format to FMT_USER.
Fixed with #210.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels