From 011dfc839d40c735fb63474aa6d5e1412b823a3b Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Thu, 16 Mar 2023 16:22:11 +0100 Subject: silence format warning more reliably --- Makefile | 3 +-- all.h | 1 + amd64/sysv.c | 2 +- arm64/abi.c | 2 +- rega.c | 2 +- util.c | 10 ++++++++++ 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index c51e283..0dbe5f7 100644 --- a/Makefile +++ b/Makefile @@ -13,8 +13,7 @@ OBJ = $(COMMOBJ) $(AMD64OBJ) $(ARM64OBJ) $(RV64OBJ) SRCALL = $(OBJ:.o=.c) -CFLAGS = $(CPPFLAGS) -std=c99 -g \ - -Wall -Wextra -Wpedantic -Wno-format-truncation +CFLAGS = -std=c99 -g -Wall -Wextra -Wpedantic qbe: $(OBJ) $(CC) $(LDFLAGS) $(OBJ) -o $@ diff --git a/all.h b/all.h index 7eba443..850803b 100644 --- a/all.h +++ b/all.h @@ -458,6 +458,7 @@ void freeall(void); void *vnew(ulong, size_t, Pool); void vfree(void *); void vgrow(void *, ulong); +void fmt(char *, char *, ...); uint32_t intern(char *); char *str(uint32_t); int argcls(Ins *, int); diff --git a/amd64/sysv.c b/amd64/sysv.c index 74db60c..6c62887 100644 --- a/amd64/sysv.c +++ b/amd64/sysv.c @@ -512,7 +512,7 @@ split(Fn *fn, Blk *b) idup(&bn->ins, curi, bn->nins); curi = &insb[NIns]; bn->visit = ++b->visit; - snprintf(bn->name, NString, "%s.%d", b->name, b->visit); + fmt(bn->name, "%s.%d", b->name, b->visit); bn->loop = b->loop; bn->link = b->link; b->link = bn; diff --git a/arm64/abi.c b/arm64/abi.c index b9d557d..18bdfc5 100644 --- a/arm64/abi.c +++ b/arm64/abi.c @@ -547,7 +547,7 @@ split(Fn *fn, Blk *b) idup(&bn->ins, curi, bn->nins); curi = &insb[NIns]; bn->visit = ++b->visit; - snprintf(bn->name, NString, "%s.%d", b->name, b->visit); + fmt(bn->name, "%s.%d", b->name, b->visit); bn->loop = b->loop; bn->link = b->link; b->link = bn; diff --git a/rega.c b/rega.c index d2d42e0..d7452a8 100644 --- a/rega.c +++ b/rega.c @@ -670,7 +670,7 @@ rega(Fn *fn) b1->link = blist; blist = b1; fn->nblk++; - snprintf(b1->name, NString, "%s_%s", b->name, s->name); + fmt(b1->name, "%s_%s", b->name, s->name); b1->nins = &insb[NIns] - curi; stmov += b1->nins; stblk += 1; diff --git a/util.c b/util.c index 8997f6c..2ab82bb 100644 --- a/util.c +++ b/util.c @@ -154,6 +154,16 @@ vgrow(void *vp, ulong len) *(Vec **)vp = v1; } +void +fmt(char *dst, char *s, ...) +{ + va_list ap; + + va_start(ap, s); + vsnprintf(dst, NString, s, ap); + va_end(ap); +} + uint32_t intern(char *s) { -- cgit 1.4.1