src: fix fmt string warnings
Florian Westphal
maintainerPATCH 1/1 src: fix fmt string warnings
for some reason several functions had a __gmp_fmtstring annotation, but that was an empty macro.
After fixing it up, we get several new warnings:
In file included from src/datatype.c:28:src/datatype.c:174:24: note: in expansion of macro 'error'
174 | return error(&sym->location,
| ^~~~~src/datatype.c:405:24: note: in expansion of macro 'error'
405 | return error(&sym->location, "Could not parse %s; did you mean `%s'?",
| ^~~~~
Fmt string says '%s', but unqailified void *, add 'const char *' cast, it is safe in both cases.
In file included from src/evaluate.c:29:src/evaluate.c: In function 'byteorder_conversion':src/evaluate.c:232:35: warning: format '%s' expects a matching 'char *' argument [-Wformat=]
232 | "Byteorder mismatch: %s expected %s, %s got %s",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Actual bug, fmt string has one '%s' too many, remove it.
All other warnings were due to '%u' instead of '%lu' / '%zu'.
--- include/erec.h | 4 ++-- include/expression.h | 2 +- include/utils.h | 5 ----- src/datatype.c | 4 ++-- src/evaluate.c | 8 ++++---- src/parser_bison.y | 2 +- 6 files changed, 10 insertions(+), 15 deletions(-)
include/erec.h +2 -2
@@ -40,10 +40,10 @@ struct error_record {extern struct error_record *erec_vcreate (enum error_record_types type,const struct location *loc,const char *fmt,va_list ap) -__gmp_fmtstring (3 ,0 ); +__fmtstring (3 ,0 );extern struct error_record *erec_create (enum error_record_types type,const struct location *loc, -const char *fmt, ...)__gmp_fmtstring (3 ,4 ); +const char *fmt, ...)__fmtstring (3 ,4 );extern void erec_add_location (struct error_record *erec,const struct location *loc);extern void erec_destroy (struct error_record *erec);
include/expression.h +1 -1
@@ -441,7 +441,7 @@ extern void expr_set_type(struct expr *expr, const struct datatype *dtype,struct eval_ctx ; extern int expr_binary_error(struct list_head *msgs, const struct expr *e1, const struct expr *e2, - const char *fmt, ...) __gmp_fmtstring(4, 5); + const char *fmt, ...) __fmtstring(4, 5); #define expr_error(msgs, expr, fmt, args...) \ expr_binary_error(msgs, expr, NULL, fmt, ## args)
include/utils.h +0 -5
@@ -27,11 +27,6 @@#endif #define __fmtstring (x, y) __attribute__((format(printf, x, y))) -#if 0 -#define __gmp_fmtstring (x, y) __fmtstring(x, y) -#else -#define __gmp_fmtstring (x, y) -#endif #define __must_check __attribute__((warn_unused_result))#define __noreturn __attribute__((__noreturn__))
src/datatype.c +2 -2
@@ -173,7 +173,7 @@ static struct error_record *__symbol_parse_fuzzy(const struct expr *sym,if (st.obj) {return error (&sym->location,"Could not parse %s expression; did you you mean `%s`?" , - sym->dtype->desc, st.obj); + sym->dtype->desc, (const char *)st.obj); }return NULL ;
@@ -403,7 +403,7 @@ static struct error_record *verdict_type_error(const struct expr *sym)if (st.obj) {return error (&sym->location,"Could not parse %s; did you mean `%s'?" , - sym->dtype->desc, st.obj); + sym->dtype->desc, (const char *)st.obj); }/* assume user would like to jump to chain as a hint. */
src/evaluate.c +4 -4
@@ -229,7 +229,7 @@ static int byteorder_conversion(struct eval_ctx *ctx, struct expr **expr,return 0 ;default :return expr_error (ctx->msgs, *expr, -"Byteorder mismatch: %s expected %s, %s got %s" , +"Byteorder mismatch: expected %s, %s got %s" , byteorder_names[byteorder],expr_name (*expr), byteorder_names[(*expr)->byteorder]);
@@ -1811,7 +1811,7 @@ static int expr_evaluate_concat(struct eval_ctx *ctx, struct expr **expr) ctx->inner_desc =NULL ;if (size >NFT_MAX_EXPR_LEN_BITS ) -return expr_error (ctx->msgs, i,"Concatenation of size %u exceeds maximum size of %u" , +return expr_error (ctx->msgs, i,"Concatenation of size %u exceeds maximum size of %lu" , size,NFT_MAX_EXPR_LEN_BITS ); }
@@ -3507,7 +3507,7 @@ static int stmt_evaluate_payload(struct eval_ctx *ctx, struct stmt *stmt)if (payload_byte_size >sizeof (data))return expr_error (ctx->msgs, stmt->payload.expr, -"uneven load cannot span more than %u bytes, got %u" , +"uneven load cannot span more than %zu bytes, got %u" ,sizeof (data), payload_byte_size);if (aligned_fetch && payload_byte_size &1 ) {
@@ -5187,7 +5187,7 @@ static int set_expr_evaluate_concat(struct eval_ctx *ctx, struct expr **expr) size +=netlink_padded_len (i->len);if (size >NFT_MAX_EXPR_LEN_BITS ) -return expr_error (ctx->msgs, i,"Concatenation of size %u exceeds maximum size of %u" , +return expr_error (ctx->msgs, i,"Concatenation of size %u exceeds maximum size of %lu" , size,NFT_MAX_EXPR_LEN_BITS ); }
src/parser_bison.y +1 -1
@@ -5863,7 +5863,7 @@ payload_expr : payload_raw_expr payload_raw_len : NUM { if ($1 > NFT_MAX_EXPR_LEN_BITS) { - erec_queue(error(&@1, "raw payload length %u exceeds upper limit of %u", + erec_queue(error(&@1, "raw payload length %lu exceeds upper limit of %lu", $1, NFT_MAX_EXPR_LEN_BITS), state->msgs); YYERROR;
Signature · 1 line
2.51.0