expr: Add const qualifiers to *2str translation arrays
PATCH 1/1 expr: Add const qualifiers to *2str translation arrays
Add const qualifiers to the "to string" translation arrays used by various *2str() functions.
This fixes GCC warnings such as the following when compiling with -Wwrite-strings:
expr/byteorder.c:176:25: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
In order to catch these in the future, also add -Wwrite-strings to default CFLAGS.
--- configure.ac | 2 +- src/expr/byteorder.c | 2 +- src/expr/cmp.c | 2 +- src/expr/dynset.c | 2 +- src/expr/payload.c | 2 +- src/expr/range.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-)
configure.ac +1 -1
@@ -40,7 +40,7 @@ AS_IF([test "x$with_json_parsing" = "xyes"], [ ]) regular_CFLAGS="-Wall -Waggregate-return -Wmissing-declarations \ -Wmissing-prototypes -Wshadow -Wstrict-prototypes \ - -Wformat=2 -pipe" + -Wformat=2 -Wwrite-strings -pipe" AC_SUBST([regular_CPPFLAGS]) AC_SUBST([regular_CFLAGS]) AC_CONFIG_FILES([Makefile src/Makefile include/Makefile include/libnftnl/Makefile include/linux/Makefile include/linux/netfilter/Makefile examples/Makefile tests/Makefile libnftnl.pc doxygen.cfg])
src/expr/byteorder.c +1 -1
@@ -172,7 +172,7 @@ nftnl_expr_byteorder_parse(struct nftnl_expr *e, struct nlattr *attr)return ret; } -static char *expr_byteorder_str[] = { +static const char *expr_byteorder_str[] = { [NFT_BYTEORDER_HTON ] ="hton" , [NFT_BYTEORDER_NTOH ] ="ntoh" , };
src/expr/cmp.c +1 -1
@@ -139,7 +139,7 @@ nftnl_expr_cmp_parse(struct nftnl_expr *e, struct nlattr *attr)return ret; } -static char *expr_cmp_str[] = { +static const char *expr_cmp_str[] = { [NFT_CMP_EQ ] ="eq" , [NFT_CMP_NEQ ] ="neq" , [NFT_CMP_LT ] ="lt" ,
src/expr/dynset.c +1 -1
@@ -258,7 +258,7 @@ nftnl_expr_dynset_export(char *buf, size_t size,return nftnl_buf_done (&b); } -static char *op2str_array[] = { +static const char *op2str_array[] = { [NFT_DYNSET_OP_ADD ] ="add" , [NFT_DYNSET_OP_UPDATE ] ="update" , };
src/expr/payload.c +1 -1
@@ -203,7 +203,7 @@ nftnl_expr_payload_parse(struct nftnl_expr *e, struct nlattr *attr)return 0 ; } -static char *base2str_array[NFT_PAYLOAD_TRANSPORT_HEADER +1 ] = { +static const char *base2str_array[NFT_PAYLOAD_TRANSPORT_HEADER +1 ] = { [NFT_PAYLOAD_LL_HEADER ] ="link" , [NFT_PAYLOAD_NETWORK_HEADER ] ="network" , [NFT_PAYLOAD_TRANSPORT_HEADER ] ="transport" ,
src/expr/range.c +1 -1
@@ -159,7 +159,7 @@ nftnl_expr_range_parse(struct nftnl_expr *e, struct nlattr *attr)return ret; } -static char *expr_range_str[] = { +static const char *expr_range_str[] = { [NFT_RANGE_EQ ] ="eq" , [NFT_RANGE_NEQ ] ="neq" , };
Signature · 1 line
2.11.0
Quoted 10 lines · Tobias Klauser
Add const qualifiers to the "to string" translation arrays used by various *2str() functions.
This fixes GCC warnings such as the following when compiling with -Wwrite-strings:
expr/byteorder.c:176:25: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]In order to catch these in the future, also add -Wwrite-strings to default CFLAGS.
Applied, thanks.