Skip to content

Commit

Permalink
Add HTS_FORMAT checks to a variety of places.
Browse files Browse the repository at this point in the history
These are needed in newer clangs with -Wformat=2.
  • Loading branch information
jkbonfield authored and daviesrob committed Aug 19, 2024
1 parent d465874 commit 8e3ef4b
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions bgzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

static const int WINDOW_SIZE = BGZF_BLOCK_SIZE;

static void error(const char *format, ...)
static void HTS_FORMAT(HTS_PRINTF_FMT, 1, 2) error(const char *format, ...)
{
va_list ap;
va_start(ap, format);
Expand Down Expand Up @@ -689,7 +689,7 @@ int main(int argc, char **argv)
if ( bgzf_index_load(fp, argv[optind], ".gzi") < 0 )
error("Could not load index: %s.gzi\n", argv[optind]);
}
if ( bgzf_useek(fp, start, SEEK_SET) < 0 ) error("Could not seek to %d-th (uncompressd) byte\n", start);
if ( bgzf_useek(fp, start, SEEK_SET) < 0 ) error("Could not seek to %ld-th (uncompressd) byte\n", start);
}

if (threads > 1)
Expand Down
2 changes: 1 addition & 1 deletion htsfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion htslib/vcf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/hfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/test-bcf-sr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/test-bcf-translate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/test-bcf_set_variant_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/test-vcf-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8e3ef4b

Please sign in to comment.