Skip to content

Commit d494f38

Browse files
committed
Add HTS_FORMAT checks to a variety of places.
These are needed in newer clangs with -Wformat=2.
1 parent 43b4a66 commit d494f38

9 files changed

+12
-10
lines changed

.cirrus.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ ubuntu_task:
113113
- environment:
114114
# Cirrus-CI's clang isn't installed with ubsan, so we do that in gcc
115115
USE_CONFIG: yes
116-
CFLAGS: -std=c99 -pedantic -Wformat -g -Wall -O3
116+
CFLAGS: -std=c99 -pedantic -Wformat -Wformat=2 -g -Wall -O3
117117
USE_LIBDEFLATE: yes
118118

119119
# NB: we could consider building a docker image with these

bgzip.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
static const int WINDOW_SIZE = BGZF_BLOCK_SIZE;
5050

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

695695
if (threads > 1)

htsfile.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int show_headers = 1;
4646
int verbose = 0;
4747
int status = EXIT_SUCCESS; /* Exit status from main */
4848

49-
void error(const char *format, ...)
49+
void HTS_FORMAT(HTS_PRINTF_FMT, 1, 2) error(const char *format, ...)
5050
{
5151
int err = errno;
5252
va_list args;

htslib/vcf.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,8 @@ set to one of BCF_ERR* codes and must be checked before calling bcf_write().
596596
int bcf_hdr_append(bcf_hdr_t *h, const char *line);
597597

598598
HTSLIB_EXPORT
599-
int bcf_hdr_printf(bcf_hdr_t *h, const char *format, ...);
599+
int bcf_hdr_printf(bcf_hdr_t *h, const char *format, ...)
600+
HTS_FORMAT(HTS_PRINTF_FMT, 2, 3);
600601

601602
/** VCF version, e.g. VCFv4.2 */
602603
HTSLIB_EXPORT

test/hfile.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ DEALINGS IN THE SOFTWARE. */
3535
#include "../htslib/hts_defs.h"
3636
#include "../htslib/kstring.h"
3737

38-
void HTS_NORETURN fail(const char *format, ...)
38+
void HTS_FORMAT(HTS_PRINTF_FMT, 1, 2) HTS_NORETURN
39+
fail(const char *format, ...)
3940
{
4041
int err = errno;
4142
va_list args;

test/test-bcf-sr.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include "../htslib/hts.h"
4141
#include "../htslib/vcf.h"
4242

43-
void error(const char *format, ...)
43+
void HTS_FORMAT(HTS_PRINTF_FMT, 1, 2) error(const char *format, ...)
4444
{
4545
va_list ap;
4646
va_start(ap, format);

test/test-bcf-translate.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
#include "../htslib/vcf.h"
3131

32-
void error(const char *format, ...)
32+
void HTS_FORMAT(HTS_PRINTF_FMT, 1, 2) error(const char *format, ...)
3333
{
3434
va_list ap;
3535
va_start(ap, format);

test/test-bcf_set_variant_type.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ DEALINGS IN THE SOFTWARE. */
2929
#include "../htslib/hts.h"
3030
#include "../vcf.c"
3131

32-
void error(const char *format, ...)
32+
void HTS_FORMAT(HTS_PRINTF_FMT, 1, 2) error(const char *format, ...)
3333
{
3434
va_list ap;
3535
va_start(ap, format);

test/test-vcf-api.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ DEALINGS IN THE SOFTWARE. */
3333
#include "../htslib/kstring.h"
3434
#include "../htslib/kseq.h"
3535

36-
void error(const char *format, ...)
36+
void HTS_FORMAT(HTS_PRINTF_FMT, 1, 2) error(const char *format, ...)
3737
{
3838
va_list ap;
3939
va_start(ap, format);

0 commit comments

Comments
 (0)