Skip to contentSkip to conversation

net: Disable the format-extra-args warning

PATCH In review Tom Rini 2 participants 3 messages May 10, 2017 – May 12, 2017 Networking

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH 1/1 net: Disable the format-extra-args warning

We will see warnings such as:
net/eth_common.c:57:61: warning: data argument not used by format string [-Wformat-extra-args]

        sprintf(enetvar, index ? "%s%daddr" : "%saddr", base_name, index);
                                              ~~~~~~~~             ^

With clang. In this case we do not want to re-write our code to be less compact as the above is intentional and readable. Add a comment above the disabling so that it's clear why we want that warning off.

---
 net/Makefile | 5 +++++
 1 file changed, 5 insertions(+)
net/Makefile +5 -0
index f03d6083268f..ae54eee5afe0 100644
@@ -25,3 +25,8 @@ obj-$(CONFIG_CMD_PING) += ping.o
 obj-$(CONFIG_CMD_RARP) += rarp.o
 obj-$(CONFIG_CMD_SNTP) += sntp.o
 obj-$(CONFIG_CMD_NET)  += tftp.o
+
+# Disable this warning as it is triggered by:
+# sprintf(buf, index ? "foo%d" : "foo", index)
+# and this is intentional usage.
+CFLAGS_eth_common.o += -Wno-format-extra-args
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 net: Disable the format-extra-args warning

Hello Tom,

right, a bit outdated knowledge, but at least more then two years ago, working around this warning would always lead to code increase and I can't think of a reason why the code can actually fail.

Suppressing the warning seems fine with me.

Regards,
Jeroen

Quoted 26 lines · Tom Rini

We will see warnings such as:
net/eth_common.c:57:61: warning: data argument not used by format string [-Wformat-extra-args]

         sprintf(enetvar, index ? "%s%daddr" : "%saddr", base_name, index);
                                               ~~~~~~~~             ^

With clang. In this case we do not want to re-write our code to be less compact as the above is intentional and readable. Add a comment above the disabling so that it's clear why we want that warning off.

---
  net/Makefile | 5 +++++
  1 file changed, 5 insertions(+)
net/Makefile +5 -0
index f03d6083268f..ae54eee5afe0 100644
@@ -25,3 +25,8 @@ obj-$(CONFIG_CMD_PING) += ping.o
  obj-$(CONFIG_CMD_RARP) += rarp.o
  obj-$(CONFIG_CMD_SNTP) += sntp.o
  obj-$(CONFIG_CMD_NET)  += tftp.o
+
+# Disable this warning as it is triggered by:
+# sprintf(buf, index ? "foo%d" : "foo", index)
+# and this is intentional usage.
+CFLAGS_eth_common.o += -Wno-format-extra-args
author
#2 lore raw
In reply to Tom Rini
Quoted 9 lines · Tom Rini

We will see warnings such as:
net/eth_common.c:57:61: warning: data argument not used by format string [-Wformat-extra-args]

        sprintf(enetvar, index ? "%s%daddr" : "%saddr", base_name, index);
                                              ~~~~~~~~             ^

With clang. In this case we do not want to re-write our code to be less compact as the above is intentional and readable. Add a comment above the disabling so that it's clear why we want that warning off.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170512/ed89b837/attachment.sig>