Skip to content

drill.c -- Avoid floating control statements #216

@henrygab

Description

@henrygab

Braces after control statements (if/else/do/while) should be mandatory.

Admittedly, when considered by itself, it would seem that omitting braces seems OK. However, this increases risk of bugs, especially with macros. In fact, the old dprintf() macro exposed exactly this type of risk:

// 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.

See SEI CERT C Coding Standard EXP19-C.

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