Skip to content

drill.c -- unsafe macros are bad #220

@henrygab

Description

@henrygab

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions