]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: fix fmt string warnings
authorFlorian Westphal <fw@strlen.de>
Fri, 17 Oct 2025 08:38:25 +0000 (10:38 +0200)
committerFlorian Westphal <fw@strlen.de>
Thu, 23 Oct 2025 12:53:50 +0000 (14:53 +0200)
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'.

Signed-off-by: Florian Westphal <fw@strlen.de>
include/erec.h
include/expression.h
include/utils.h
src/datatype.c
src/evaluate.c
src/parser_bison.y

index c17f5def530213dae415b0301743d8ade1f92438..8ad5d83a705dbe033908c21af63c7c622de0436b 100644 (file)
@@ -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);
index e73ad90e7e5da0256a81b63db743ee537fd573c5..a960f8cb8b087ac44f482b0161e5cf8788e0b7f6 100644 (file)
@@ -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)
index e18fabec56ba35af984c71ac2a25ba3d0e9324d1..474c7595f7cdc2a3fcd55511176c2af047814207 100644 (file)
 #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__))
index f347010f4a1af8c6ce556c1e1f418dd1dfadacbb..956ce2ac0a97bc38d5f302830adc7b6635d3d198 100644 (file)
@@ -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. */
index a5cc4181919897a4d7c4e679730eb20d1408c438..ffd3ce6268598921140f58b234a0265b2d40df8a 100644 (file)
@@ -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);
        }
 
index 3c21c7584d01fb296f8a7ddeef7919dd04faec13..52730f71b8805f423193658820a973a3cc1c5d46 100644 (file)
@@ -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;