From b5ee95fc07f7fa0e25e5f52b526cba15f414e7d1 Mon Sep 17 00:00:00 2001 From: James Bonfield Date: Thu, 22 Aug 2024 14:16:25 +0100 Subject: [PATCH] Add more warnings. These find an old bug-let in hts_parse_format(): The buffer size is 8, but it includes \0 so the string would have been truncated, causing the strcmp to fail for "fastq.gz". Curiously gcc 10 and 11 spot this, but not gcc 12 or 13, nor clang. --- .cirrus.yml | 2 +- hts.c | 2 +- test/test-bcf-sr.c | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 61f094c2b..0039f8c07 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -141,7 +141,7 @@ rocky_task: LC_ALL: C CIRRUS_CLONE_DEPTH: 1 USE_CONFIG: yes - CFLAGS: -std=gnu90 -Wformat -Wformat=2 + CFLAGS: -g -O3 -std=gnu90 -Wformat -Wformat=2 -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers -Wno-empty-body # NB: we could consider building a docker image with these # preinstalled and specifying that instead, to speed up testing. diff --git a/hts.c b/hts.c index 42be3f21f..a4ae32a69 100644 --- a/hts.c +++ b/hts.c @@ -1322,7 +1322,7 @@ int hts_parse_opt_list(htsFormat *fmt, const char *str) { * -1 on failure. */ int hts_parse_format(htsFormat *format, const char *str) { - char fmt[8]; + char fmt[9]; const char *cp = scan_keyword(str, ',', fmt, sizeof fmt); format->version.minor = 0; // unknown diff --git a/test/test-bcf-sr.c b/test/test-bcf-sr.c index b4943b5ef..e24954685 100644 --- a/test/test-bcf-sr.c +++ b/test/test-bcf-sr.c @@ -179,6 +179,7 @@ int main(int argc, char *argv[]) break; case 'h': usage(EXIT_SUCCESS); + // fall-through default: usage(EXIT_FAILURE); } }