nbd: Silence Coverity false positive
PATCH 1/1 nbd: Silence Coverity false positive
Coverity noticed (CID 1436125) that we check the return value of nbd_extent_array_add in most places, but not at the end of bitmap_to_extents(). The return value exists to break loops before a future iteration, so there is nothing to check if we are already done iterating. That said, a minor rearrangement to the code plus a better comment pacifies Coverity.
---
Not a show-stopper by itself for 5.2, but perhaps worth including in -rc2 if I collect other more-important patches.
nbd/server.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
nbd/server.c +2 -3
@@ -2128,9 +2128,8 @@ static void bitmap_to_extents(BdrvDirtyBitmap *bitmap, } } -if (!full) { -/* last non dirty extent */ -nbd_extent_array_add (es, end - start,0 ); +if (!full &&nbd_extent_array_add (es, end - start,0 ) <0 ) { +/* last non dirty extent, nothing to do if array was already full */ }bdrv_dirty_bitmap_unlock (bitmap);
Signature · 1 line
2.28.0
nbd/server.c static void bitmap_to_extents(BdrvDirtyBitmap *bitmap, · line 2133
Quoted 6 lines · Eric Blake
nbd/server.c +2
-3-if (!full) { -/* last non dirty extent */ -nbd_extent_array_add (es, end - start,0 ); +if (!full &&nbd_extent_array_add (es, end - start,0 ) <0 ) { +/* last non dirty extent, nothing to do if array was already full */ }
Casting to (void) is another way to get rid of the warning.
I dunno which makes more sense here. Definitely the comment is helpful.
r~
Quoted 11 lines · Richard Henderson
nbd/server.c static void bitmap_to_extents(BdrvDirtyBitmap *bitmap, · line 2133
Quoted 6 lines · Eric Blake
nbd/server.c +2
-3-if (!full) { -/* last non dirty extent */ -nbd_extent_array_add (es, end - start,0 ); +if (!full &&nbd_extent_array_add (es, end - start,0 ) <0 ) { +/* last non dirty extent, nothing to do if array was already full */ }Casting to (void) is another way to get rid of the warning.
I dunno which makes more sense here. Definitely the comment is helpful.
As in:
if (!full) {
/* last non dirty extent, nothing to do if array is now full */
(void) nbd_extent_array_add(es, end - start, 0);
}Yeah, that looks a little better. Should I post that as v2, or wait for further comments on this?
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Richard Henderson
Reviewed-byQuoted 11 lines · Eric Blake
Quoted 10 lines · Richard Henderson
nbd/server.c static void bitmap_to_extents(BdrvDirtyBitmap *bitmap, · line 2133
Quoted 6 lines · Eric Blake
nbd/server.c +2
-3-if (!full) { -/* last non dirty extent */ -nbd_extent_array_add (es, end - start,0 ); +if (!full &&nbd_extent_array_add (es, end - start,0 ) <0 ) { +/* last non dirty extent, nothing to do if array was already full */ }Casting to (void) is another way to get rid of the warning.
Quoted 8 lines
Quoted 1 line
I dunno which makes more sense here. Definitely the comment is helpful.
As in:
if (!full) { /* last non dirty extent, nothing to do if array is now full */ (void) nbd_extent_array_add(es, end - start, 0); }
Yep.
Quoted 2 lines
Yeah, that looks a little better. Should I post that as v2, or wait for further comments on this?
Up to you. You can have my
for either version.
r~