slirp: Gcc 9 -O3 fix
PATCH 1/1 slirp: Gcc 9 -O3 fix
From: "Dr. David Alan Gilbert" <[email protected]>
Gcc 9 needs some convincing that sopreprbuf really is going to fill in iov in the call from soreadbuf, even though the failure case shouldn't happen; so swing the check around initialising the fields.
--- slirp/src/socket.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
slirp/src/socket.c +5 -3
@@ -113,12 +113,14 @@ size_t sopreprbuf(struct socket *so, struct iovec *iov, int *np)DEBUG_CALL ("sopreprbuf" );DEBUG_ARG ("so = %p" , so); -if (len <=0 ) -return 0 ; - iov[0 ].iov_base = sb->sb_wptr; + iov[0 ].iov_len =0 ; iov[1 ].iov_base =NULL ; iov[1 ].iov_len =0 ; + +if (len <=0 ) +return 0 ; +if (sb->sb_wptr < sb->sb_rptr) { iov[0 ].iov_len = sb->sb_rptr - sb->sb_wptr;/* Should never succeed, but... */
Signature · 1 line
2.21.0
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH] slirp: Gcc 9 -O3 fix
Type: series
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'c02eccdeb3 slirp: Gcc 9 -O3 fix
=== OUTPUT BEGIN ===
ERROR: code indent should never use tabs
#22: FILE: slirp/src/socket.c:116:
+^Iiov[0].iov_base = sb->sb_wptr;$
total: 1 errors, 0 warnings, 17 lines checked
Commit c02eccdeb3e6 (slirp: Gcc 9 -O3 fix) has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Hello,
Dr. David Alan Gilbert (git), le ven. 05 avril 2019 19:46:48 +0100, a ecrit:
Quoted 5 lines
From: "Dr. David Alan Gilbert" <[email protected]>
Gcc 9 needs some convincing that sopreprbuf really is going to fill in iov in the call from soreadbuf, even though the failure case shouldn't happen; so swing the check around initialising the fields.
While I can understand that setting iov[0].iov_len may help a compiler, I don't see why moving if (len <= 0) return 0; down?
Quoted 30 lines
Signed-off-by Dr. David Alan Gilbert <[email protected]>--- slirp/src/socket.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)slirp/src/socket.c +5
-3@@ -113,12 +113,14 @@ size_t sopreprbuf(struct socket *so, struct iovec *iov, int *np)DEBUG_CALL ("sopreprbuf" );DEBUG_ARG ("so = %p" , so); -if (len <=0 ) -return 0 ; - iov[0 ].iov_base = sb->sb_wptr; + iov[0 ].iov_len =0 ; iov[1 ].iov_base =NULL ; iov[1 ].iov_len =0 ; + +if (len <=0 ) +return 0 ; +if (sb->sb_wptr < sb->sb_rptr) { iov[0 ].iov_len = sb->sb_rptr - sb->sb_wptr;/* Should never succeed, but... */ Signature · 1 line
2.21.0
Signature · 5 lines
Samuel FYLG> Tiens, vlà une URL qui va bien : FYLG> ftp://127.0.0.1/WaReZ/NiouZeS/WinDoZe/NeWSMoNGeR/SuPeR c'est gentil sauf que l'adresse ne fonctionne pas sa me fais une erreur -+- Furtif in Guide du Neuneu Usenet : <MODE CERVEAU OFF> -+-
Quoted 11 lines · * Samuel Thibault ([email protected]) wrote:
Hello,
Dr. David Alan Gilbert (git), le ven. 05 avril 2019 19:46:48 +0100, a ecrit:
Quoted 5 lines
From: "Dr. David Alan Gilbert" <[email protected]>
Gcc 9 needs some convincing that sopreprbuf really is going to fill in iov in the call from soreadbuf, even though the failure case shouldn't happen; so swing the check around initialising the fields.
While I can understand that setting iov[0].iov_len may help a compiler, I don't see why moving if (len <= 0) return 0; down?
The original errors are:/home/dgilbert/git/qemu/slirp/src/socket.c: In function ‘soread’:/home/dgilbert/git/qemu/slirp/src/socket.c:188:7: error: ‘iov.iov_base’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
188 | nn = recv(so->s, iov[0].iov_base, iov[0].iov_len,0);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/dgilbert/git/qemu/slirp/src/socket.c:188:7: error: ‘iov.iov_len’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
/home/dgilbert/git/qemu/slirp/src/socket.c:232:5: error: ‘n’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
232 | if (n == 2 && nn == iov[0].iov_len) {
| ^/home/dgilbert/git/qemu/slirp/src/socket.c:234:19: error: ‘*((void *)&iov+16).iov_len’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
(and a few more along the same idea).
So the problem is actually in soread not sopreprbuf itself.
'soread' has the comment:
/*
* No need to check if there's enough room to read.
* soread wouldn't have been called if there weren't
*/
sopreprbuf(so, iov, &n);the compiler doesn't realise that, and is moaning about the case where the if (len <=0) return happens and the following code tries to use iov.
Dave
Quoted 22 lines
Quoted 22 lines
Signed-off-by Dr. David Alan Gilbert <[email protected]>--- slirp/src/socket.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)slirp/src/socket.c +3
-3@@ -113,12 +113,14 @@ size_t sopreprbuf(struct socket *so, struct iovec *iov, int *np)DEBUG_CALL ("sopreprbuf" );DEBUG_ARG ("so = %p" , so); -if (len <=0 ) -return 0 ; - iov[0 ].iov_base = sb->sb_wptr; + iov[0 ].iov_len =0 ; iov[1 ].iov_base =NULL ; iov[1 ].iov_len =0 ; + +if (len <=0 )
Quoted 15 lines
Quoted 8 lines
slirp/src/socket.c +2
-0+return 0 ; +if (sb->sb_wptr < sb->sb_rptr) { iov[0 ].iov_len = sb->sb_rptr - sb->sb_wptr;/* Should never succeed, but... */ Signature · 1 line
2.21.0Signature · 5 lines
Samuel FYLG> Tiens, vlà une URL qui va bien : FYLG> ftp://127.0.0.1/WaReZ/NiouZeS/WinDoZe/NeWSMoNGeR/SuPeR c'est gentil sauf que l'adresse ne fonctionne pas sa me fais une erreur -+- Furtif in Guide du Neuneu Usenet : <MODE CERVEAU OFF> -+-
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Hello,
Dr. David Alan Gilbert, le lun. 08 avril 2019 09:46:53 +0100, a ecrit:
Quoted 11 lines
'soread' has the comment:
/* * No need to check if there's enough room to read. * soread wouldn't have been called if there weren't */ sopreprbuf(so, iov, &n);the compiler doesn't realise that, and is moaning about the case where the if (len <=0) return happens and the following code tries to use iov.
I see. Perhaps we should make this an assert then? In case this isn't true, i.e. soread() is called even if no room is available, returning 0 would probably just let the caller just try again, and we should rather just plainly crash than hang?
Samuel
Quoted 11 lines · * Samuel Thibault ([email protected]) wrote:
Hello,
Dr. David Alan Gilbert, le lun. 08 avril 2019 09:46:53 +0100, a ecrit:
Quoted 8 lines
'soread' has the comment:
/* * No need to check if there's enough room to read. * soread wouldn't have been called if there weren't */ sopreprbuf(so, iov, &n);
Quoted 8 lines
Quoted 3 lines
the compiler doesn't realise that, and is moaning about the case where the if (len <=0) return happens and the following code tries to use iov.
I see. Perhaps we should make this an assert then? In case this isn't true, i.e.
soread()is called even if no room is available, returning 0 would probably just let the caller just try again, and we should rather just plainly crash than hang?
Adding the assert in soread sorts that case out:
assert(sopreprbuf(so, iov, &n) != 0);
however, I also need to fix soreadbuf; is it legal to call that with a 0 size?
Dave
Quoted 1 line
Samuel
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Dr. David Alan Gilbert, le ven. 12 avril 2019 16:49:42 +0100, a ecrit:
Quoted 21 lines · * Samuel Thibault ([email protected]) wrote:
Quoted 11 lines
Hello,
Dr. David Alan Gilbert, le lun. 08 avril 2019 09:46:53 +0100, a ecrit:
Quoted 8 lines
'soread' has the comment:
/* * No need to check if there's enough room to read. * soread wouldn't have been called if there weren't */ sopreprbuf(so, iov, &n);Quoted 8 lines
Quoted 3 lines
the compiler doesn't realise that, and is moaning about the case where the if (len <=0) return happens and the following code tries to use iov.
I see. Perhaps we should make this an assert then? In case this isn't true, i.e.
soread()is called even if no room is available, returning 0 would probably just let the caller just try again, and we should rather just plainly crash than hang?
Quoted 5 lines
Adding the assert in soread sorts that case out:
assert(sopreprbuf(so, iov, &n) != 0);however, I also need to fix soreadbuf; is it legal to call that with a 0 size?
It does not really make sense to, so an assert >0 should be fine.
Samuel
Quoted 22 lines · * Samuel Thibault ([email protected]) wrote:
Dr. David Alan Gilbert, le ven. 12 avril 2019 16:49:42 +0100, a ecrit:
Quoted 21 lines · * Samuel Thibault ([email protected]) wrote:
Quoted 19 lines
Hello,
Dr. David Alan Gilbert, le lun. 08 avril 2019 09:46:53 +0100, a ecrit:
Quoted 11 lines
'soread' has the comment:
/* * No need to check if there's enough room to read. * soread wouldn't have been called if there weren't */ sopreprbuf(so, iov, &n);the compiler doesn't realise that, and is moaning about the case where the if (len <=0) return happens and the following code tries to use iov.
I see. Perhaps we should make this an assert then? In case this isn't true, i.e.
soread()is called even if no room is available, returning 0 would probably just let the caller just try again, and we should rather just plainly crash than hang?
Quoted 7 lines
Quoted 5 lines
Adding the assert in soread sorts that case out:
assert(sopreprbuf(so, iov, &n) != 0);however, I also need to fix soreadbuf; is it legal to call that with a 0 size?
It does not really make sense to, so an assert >0 should be fine.
OK, replacement patch with just a couple of asserts sent.
Dave
Quoted 1 line
Samuel
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK