Skip to content

htsselftest: 'result' may be used uninitialized in the coucal bench loop (-Wmaybe-uninitialized) #736

Description

@xroche

gcc -O2 warns on master:

src/htsselftest.c:1559:12: warning: 'result' may be used uninitialized [-Wmaybe-uninitialized]

In the coucal bench loop, int result is assigned inside an if/else if chain over the six bench[].type values and then read by if (!result). Every enumerator is covered and the table only holds those six, so the read is unreachable today, but nothing in the code says so and gcc cannot prove it: adding a seventh enumerator would silently read a garbage stack slot and either pass a failed check or abort a good run.

int result = 0; at the declaration fixes it, and fails closed — an unhandled type reports failure rather than whatever was on the stack.

Confirmed pre-existing by compiling master's htsselftest.c against master's headers; the line dates to #427. Noticed while building #718, which shifts it to line 1563 but does not touch that function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions