From 6afcb53f89132c3859029b21f915846237911286 Mon Sep 17 00:00:00 2001 From: James Bonfield Date: Thu, 15 Aug 2024 16:14:56 +0100 Subject: [PATCH] Add HTS_FORMAT checks to a variety of places. These are needed in newer clangs with -Wformat=2. --- .cirrus.yml | 2 +- htsfile.c | 2 +- htslib/vcf.h | 3 ++- test/hfile.c | 3 ++- test/test-bcf-sr.c | 2 +- test/test-bcf-translate.c | 2 +- test/test-bcf_set_variant_type.c | 2 +- test/test-vcf-api.c | 2 +- 8 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 9d80ea07df..61f094c2b1 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -113,7 +113,7 @@ ubuntu_task: - environment: # Cirrus-CI's clang isn't installed with ubsan, so we do that in gcc USE_CONFIG: yes - CFLAGS: -std=c99 -pedantic -Wformat -g -Wall -O3 + CFLAGS: -std=c99 -pedantic -Wformat -Wformat=2 -g -Wall -O3 USE_LIBDEFLATE: yes # NB: we could consider building a docker image with these diff --git a/htsfile.c b/htsfile.c index 9af4ae31bc..25af3f5846 100644 --- a/htsfile.c +++ b/htsfile.c @@ -46,7 +46,7 @@ int show_headers = 1; int verbose = 0; int status = EXIT_SUCCESS; /* Exit status from main */ -void error(const char *format, ...) +void HTS_FORMAT(HTS_PRINTF_FMT, 1, 2) error(const char *format, ...) { int err = errno; va_list args; diff --git a/htslib/vcf.h b/htslib/vcf.h index e60911ab5e..9a36cab058 100644 --- a/htslib/vcf.h +++ b/htslib/vcf.h @@ -596,7 +596,8 @@ set to one of BCF_ERR* codes and must be checked before calling bcf_write(). int bcf_hdr_append(bcf_hdr_t *h, const char *line); HTSLIB_EXPORT - int bcf_hdr_printf(bcf_hdr_t *h, const char *format, ...); + int bcf_hdr_printf(bcf_hdr_t *h, const char *format, ...) + HTS_FORMAT(HTS_PRINTF_FMT, 2, 3); /** VCF version, e.g. VCFv4.2 */ HTSLIB_EXPORT diff --git a/test/hfile.c b/test/hfile.c index 8f06a971f3..741cf7a8dc 100644 --- a/test/hfile.c +++ b/test/hfile.c @@ -35,7 +35,8 @@ DEALINGS IN THE SOFTWARE. */ #include "../htslib/hts_defs.h" #include "../htslib/kstring.h" -void HTS_NORETURN fail(const char *format, ...) +void HTS_FORMAT(HTS_PRINTF_FMT, 1, 2) HTS_NORETURN +fail(const char *format, ...) { int err = errno; va_list args; diff --git a/test/test-bcf-sr.c b/test/test-bcf-sr.c index 80daf04230..b4943b5eff 100644 --- a/test/test-bcf-sr.c +++ b/test/test-bcf-sr.c @@ -40,7 +40,7 @@ #include "../htslib/hts.h" #include "../htslib/vcf.h" -void error(const char *format, ...) +void HTS_FORMAT(HTS_PRINTF_FMT, 1, 2) error(const char *format, ...) { va_list ap; va_start(ap, format); diff --git a/test/test-bcf-translate.c b/test/test-bcf-translate.c index c2f069e398..263e71eb86 100644 --- a/test/test-bcf-translate.c +++ b/test/test-bcf-translate.c @@ -29,7 +29,7 @@ #include "../htslib/vcf.h" -void error(const char *format, ...) +void HTS_FORMAT(HTS_PRINTF_FMT, 1, 2) error(const char *format, ...) { va_list ap; va_start(ap, format); diff --git a/test/test-bcf_set_variant_type.c b/test/test-bcf_set_variant_type.c index 3688609f6c..eb12ecde37 100644 --- a/test/test-bcf_set_variant_type.c +++ b/test/test-bcf_set_variant_type.c @@ -29,7 +29,7 @@ DEALINGS IN THE SOFTWARE. */ #include "../htslib/hts.h" #include "../vcf.c" -void error(const char *format, ...) +void HTS_FORMAT(HTS_PRINTF_FMT, 1, 2) error(const char *format, ...) { va_list ap; va_start(ap, format); diff --git a/test/test-vcf-api.c b/test/test-vcf-api.c index ff16fa1941..b86b71d992 100644 --- a/test/test-vcf-api.c +++ b/test/test-vcf-api.c @@ -33,7 +33,7 @@ DEALINGS IN THE SOFTWARE. */ #include "../htslib/kstring.h" #include "../htslib/kseq.h" -void error(const char *format, ...) +void HTS_FORMAT(HTS_PRINTF_FMT, 1, 2) error(const char *format, ...) { va_list ap; va_start(ap, format);