Skip to content

Add Wformat=2 and sanitize=undefined to the CI system#2101

Merged
whitwham merged 4 commits into
samtools:developfrom
jkbonfield:Wformat=2
Aug 21, 2024
Merged

Add Wformat=2 and sanitize=undefined to the CI system#2101
whitwham merged 4 commits into
samtools:developfrom
jkbonfield:Wformat=2

Conversation

@jkbonfield

Copy link
Copy Markdown
Contributor

As requested.

Wformat=2 is a bit of a pain, but undefined behaviour sanitizer seems valid to use. non-literal format checking is more questionable. It is finding bugs, although oddly in things that it ought to have been spotting before already (so maybe this coincided with a compiler version update on mingw), but it also has false positives to work around: i.e. places that aren't demonstrably the wrong arguments but cannot be validated at compile time are still considered to be wrong.

Comment thread bam_ampliconclip.c Outdated
// there is little we can do other than elide this warning for this piece of
// code. This is probably the lesser of two evils.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An easier solution here would be to always pass the full format list to sscanf() and then use the return value to see how many of them it managed to fill out. Checking against num_columns should ensure that it hasn't been confused by whitespace other than tabs.

@jkbonfield jkbonfield force-pushed the Wformat=2 branch 4 times, most recently from c57c6c1 to c6ef58e Compare August 20, 2024 09:01
@jkbonfield

Copy link
Copy Markdown
Contributor Author

I think I've finally beaten it into submission, and fixed several ampliconclip bugs related to parsing of BED files too which were instigated by attempting to work around some of the more aggressive warnings. So not found as errors due to the warnings, but serendipity at play.

This is enabled via -Wformat=2, but it causes a number of warnings.
Some are trivial to fix, needing simply a format attribute, others
less so.

Specifically ampliconclip constructs a format string based on the
number of columns detected in the bed file.  Fundamentally this
isn't compatible with the format checking.  However Rob points out an
easier way of doing this by looking at sscanf return values, and it
turns out this also fixes a whole swathe of unrelated recent
ampliconclip bugs.

Also fixed a newly detected formatting problem (albeit 32-bit
platforms only and only in error reporting) in tmp_file.c.
The size check for "num_columns > sizeof(scanf_components)" is wrong,
meaning with more columns than 6 we had a read buffer overrun.  The
code also required tabs, but the BED format does not strictly state
this.

The original code prior to samtools#2033 just uses sscanf and no tab counting,
which is better as it supports any white space and matches the BED
spec (bar the weird oddity of permitting spaces in names if only
single tabs are used, but that's a nasty case we have no desire to
support).

Instead we rely on the return value from sscanf to inform us of the
(minimum) number of columns detected.

Also amended the test data to incorporate up to 12 columns and down to
3 to validate the code can still parse correctly, plus spaces instead
of tabs.
The -Wimplicit-fallthrough one spotted a genuine error too where the
new "samtools split -p" accidentally also enabled --no-PG.
@whitwham whitwham self-assigned this Aug 21, 2024
@whitwham whitwham merged commit b72dceb into samtools:develop Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants