Skip to contentSkip to conversation

net/dump.c: Suppress spurious compiler warning

PATCH In review Philipp Tomsich 3 participants 4 messages Jan 9, 2022 – Jan 12, 2022 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/dump.c: Suppress spurious compiler warning

Compiling with gcc version 11.2.0 (Ubuntu 11.2.0-13ubuntu1) results in a (spurious) warning:

In function ‘dump_receive_iov’,
inlined from ‘filter_dump_receive_iov’ at ../net/dump.c:157:5:
../net/dump.c:89:9: error: ‘writev’ specified size 18446744073709551600 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]

     89 |     if (writev(s->fd, dumpiov, cnt + 1) != sizeof(hdr) + caplen) {
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  In file included from /home/ptomsich/qemu/include/qemu/osdep.h:108,
                   from ../net/dump.c:25:

../net/dump.c: In function ‘filter_dump_receive_iov’:
/usr/include/x86_64-linux-gnu/sys/uio.h:52:16: note: in a call to function ‘writev’ declared with attribute ‘read_only (2, 3)’
52 | extern ssize_t writev (int __fd, const struct iovec *__iovec, int __count)
| ^~~~~~
cc1: all warnings being treated as errors

This change helps that version of GCC to understand what is going on and suppresses this warning.

---

 net/dump.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/dump.c +1 -1
index a07ba62401..c32d3bf4e6 100644
@@ -86,7 +86,7 @@ static ssize_t dump_receive_iov(DumpState *s, const struct iovec *iov, int cnt)
     dumpiov[0].iov_len = sizeof(hdr);
     cnt = iov_copy(&dumpiov[1], cnt, iov, cnt, 0, caplen);
 
-    if (writev(s->fd, dumpiov, cnt + 1) != sizeof(hdr) + caplen) {
+    if (writev(s->fd, &dumpiov[0], cnt + 1) != sizeof(hdr) + caplen) {
         error_report("network dump write error - stopping dump");
         close(s->fd);
         s->fd = -1;
Signature · 1 line
2.33.1
#1 lore raw

Cc'ing Richard & Eric for dubious compiler warning.

Quoted 39 lines · Philipp Tomsich

Compiling with gcc version 11.2.0 (Ubuntu 11.2.0-13ubuntu1) results in a (spurious) warning:

In function ‘dump_receive_iov’,
inlined from ‘filter_dump_receive_iov’ at ../net/dump.c:157:5:
../net/dump.c:89:9: error: ‘writev’ specified size 18446744073709551600 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]

     89 |     if (writev(s->fd, dumpiov, cnt + 1) != sizeof(hdr) + caplen) {
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  In file included from /home/ptomsich/qemu/include/qemu/osdep.h:108,
                   from ../net/dump.c:25:

../net/dump.c: In function ‘filter_dump_receive_iov’:
/usr/include/x86_64-linux-gnu/sys/uio.h:52:16: note: in a call to function ‘writev’ declared with attribute ‘read_only (2, 3)’
52 | extern ssize_t writev (int __fd, const struct iovec *__iovec, int __count)
| ^~~~~~
cc1: all warnings being treated as errors

This change helps that version of GCC to understand what is going on and suppresses this warning.

---

 net/dump.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/dump.c +1 -1
index a07ba62401..c32d3bf4e6 100644
@@ -86,7 +86,7 @@ static ssize_t dump_receive_iov(DumpState *s, const struct iovec *iov, int cnt)
     dumpiov[0].iov_len = sizeof(hdr);
     cnt = iov_copy(&dumpiov[1], cnt, iov, cnt, 0, caplen);
 
-    if (writev(s->fd, dumpiov, cnt + 1) != sizeof(hdr) + caplen) {
+    if (writev(s->fd, &dumpiov[0], cnt + 1) != sizeof(hdr) + caplen) {
         error_report("network dump write error - stopping dump");
         close(s->fd);
         s->fd = -1;
#2 lore raw

Note that I don't expect this to get applied. I just put it onto the list for visibility and to make the workaround available for downstream users that might run into the issue while Ubuntu 22.04 is maturing. I won't have any time to dig into this on the GCC side until GCC12 is out.

Philipp.

Quoted 49 lines · Philippe Mathieu-Daudé

Cc'ing Richard & Eric for dubious compiler warning.

Quoted 6 lines · Philipp Tomsich

Compiling with gcc version 11.2.0 (Ubuntu 11.2.0-13ubuntu1) results in a (spurious) warning:

In function ‘dump_receive_iov’,
inlined from ‘filter_dump_receive_iov’ at ../net/dump.c:157:5:
../net/dump.c:89:9: error: ‘writev’ specified size

18446744073709551600 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]

Quoted 1 line
     89 |     if (writev(s->fd, dumpiov, cnt + 1) != sizeof(hdr) +

caplen) {

Quoted 5 lines
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  In file included from /home/ptomsich/qemu/include/qemu/osdep.h:108,
                   from ../net/dump.c:25:

../net/dump.c: In function ‘filter_dump_receive_iov’:
/usr/include/x86_64-linux-gnu/sys/uio.h:52:16: note: in a call to

function ‘writev’ declared with attribute ‘read_only (2, 3)’

Quoted 1 line

52 | extern ssize_t writev (int __fd, const struct iovec *__iovec,

int __count)

net/dump.c static ssize_t dump_receive_iov(DumpState *s, const

Quoted 18 lines
        |                ^~~~~~

cc1: all warnings being treated as errors

This change helps that version of GCC to understand what is going on and suppresses this warning.

---

 net/dump.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/dump.c +0 -0
index a07ba62401..c32d3bf4e6 100644
@@ -86,7 +86,7 @@ static ssize_t dump_receive_iov(DumpState *s, const

struct iovec *iov, int cnt)

Quoted 8 lines
net/dump.c +1 -1
     dumpiov[0].iov_len = sizeof(hdr);
     cnt = iov_copy(&dumpiov[1], cnt, iov, cnt, 0, caplen);
 
-    if (writev(s->fd, dumpiov, cnt + 1) != sizeof(hdr) + caplen) {
+    if (writev(s->fd, &dumpiov[0], cnt + 1) != sizeof(hdr) + caplen) {
         error_report("network dump write error - stopping dump");
         close(s->fd);
         s->fd = -1;
Reviewed-by
#3 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 18 lines · Philippe Mathieu-Daudé

Cc'ing Richard & Eric for dubious compiler warning.

Quoted 15 lines · Philipp Tomsich

Compiling with gcc version 11.2.0 (Ubuntu 11.2.0-13ubuntu1) results in a (spurious) warning:

In function ‘dump_receive_iov’,
inlined from ‘filter_dump_receive_iov’ at ../net/dump.c:157:5:
../net/dump.c:89:9: error: ‘writev’ specified size 18446744073709551600 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]

     89 |     if (writev(s->fd, dumpiov, cnt + 1) != sizeof(hdr) + caplen) {
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  In file included from /home/ptomsich/qemu/include/qemu/osdep.h:108,
                   from ../net/dump.c:25:

../net/dump.c: In function ‘filter_dump_receive_iov’:
/usr/include/x86_64-linux-gnu/sys/uio.h:52:16: note: in a call to function ‘writev’ declared with attribute ‘read_only (2, 3)’
52 | extern ssize_t writev (int __fd, const struct iovec *__iovec, int __count)
| ^~~~~~
cc1: all warnings being treated as errors

That is an odd error message.

Quoted 19 lines
Quoted 19 lines

This change helps that version of GCC to understand what is going on and suppresses this warning.

---

 net/dump.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/dump.c +0 -0
index a07ba62401..c32d3bf4e6 100644
@@ -86,7 +86,7 @@ static ssize_t dump_receive_iov(DumpState *s, const struct iovec *iov, int cnt)
     dumpiov[0].iov_len = sizeof(hdr);
     cnt = iov_copy(&dumpiov[1], cnt, iov, cnt, 0, caplen);
 
Quoted 2 lines

net/dump.c static ssize_t dump_receive_iov(DumpState *s, const struct iovec *iov, int cnt) · line 89

Quoted 2 lines
net/dump.c +1 -1
-    if (writev(s->fd, dumpiov, cnt + 1) != sizeof(hdr) + caplen) {
+    if (writev(s->fd, &dumpiov[0], cnt + 1) != sizeof(hdr) + caplen) {

This change is safe; it results in the same pointer. Obviously, the latter spelling is able to provide the compiler with a bit more type information about the pointer, so that it no longer assumes a pointer to an unbounded array, so if it silences the warning, I see no downside in including it whether or not gcc is also patched to avoid creating a spurious warning in the first place.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org