* [PULL 1/2] block/snapshot: Fix compiler warning with -Wshadow=local
2023-11-13 9:36 [PULL 0/2] -Wshadow=local patches for 2023-11-13 Markus Armbruster
@ 2023-11-13 9:36 ` Markus Armbruster
2023-11-13 9:36 ` [PULL 2/2] meson: Enable -Wshadow=local Markus Armbruster
2023-11-13 19:27 ` [PULL 0/2] -Wshadow=local patches for 2023-11-13 Stefan Hajnoczi
2 siblings, 0 replies; 4+ messages in thread
From: Markus Armbruster @ 2023-11-13 9:36 UTC (permalink / raw)
To: qemu-devel; +Cc: stefanha, Thomas Huth
From: Thomas Huth <thuth@redhat.com>
No need to declare a new variable in the the inner code block
here, we can re-use the "ret" variable that has been declared
at the beginning of the function. With this change, the code
can now be successfully compiled with -Wshadow=local again.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-ID: <20231023175038.111607-1-thuth@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
block/snapshot.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/block/snapshot.c b/block/snapshot.c
index 6e16eb803a..55974273ae 100644
--- a/block/snapshot.c
+++ b/block/snapshot.c
@@ -629,7 +629,6 @@ int bdrv_all_goto_snapshot(const char *name,
while (iterbdrvs) {
BlockDriverState *bs = iterbdrvs->data;
AioContext *ctx = bdrv_get_aio_context(bs);
- int ret = 0;
bool all_snapshots_includes_bs;
aio_context_acquire(ctx);
@@ -637,9 +636,8 @@ int bdrv_all_goto_snapshot(const char *name,
all_snapshots_includes_bs = bdrv_all_snapshots_includes_bs(bs);
bdrv_graph_rdunlock_main_loop();
- if (devices || all_snapshots_includes_bs) {
- ret = bdrv_snapshot_goto(bs, name, errp);
- }
+ ret = (devices || all_snapshots_includes_bs) ?
+ bdrv_snapshot_goto(bs, name, errp) : 0;
aio_context_release(ctx);
if (ret < 0) {
bdrv_graph_rdlock_main_loop();
--
2.41.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PULL 2/2] meson: Enable -Wshadow=local
2023-11-13 9:36 [PULL 0/2] -Wshadow=local patches for 2023-11-13 Markus Armbruster
2023-11-13 9:36 ` [PULL 1/2] block/snapshot: Fix compiler warning with -Wshadow=local Markus Armbruster
@ 2023-11-13 9:36 ` Markus Armbruster
2023-11-13 19:27 ` [PULL 0/2] -Wshadow=local patches for 2023-11-13 Stefan Hajnoczi
2 siblings, 0 replies; 4+ messages in thread
From: Markus Armbruster @ 2023-11-13 9:36 UTC (permalink / raw)
To: qemu-devel; +Cc: stefanha, Thomas Huth, Philippe Mathieu-Daudé
Local variables shadowing other local variables or parameters make the
code needlessly hard to understand. Bugs love to hide in such code.
Evidence: commit bbde656263d (migration/rdma: Fix save_page method to
fail on polling error).
Enable -Wshadow=local to prevent such issues. Possible thanks to
recent cleanups. Enabling -Wshadow would prevent more issues, but
we're not yet ready for that.
As usual, the warning is only enabled when the compiler recognizes it.
GCC does, Clang doesn't.
Some shadowed locals remain in bsd-user. Since BSD prefers Clang,
let's not wait for its cleanup.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20231026053115.2066744-2-armbru@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
meson.build | 1 +
1 file changed, 1 insertion(+)
diff --git a/meson.build b/meson.build
index d7d841e71e..ec01f8b138 100644
--- a/meson.build
+++ b/meson.build
@@ -462,6 +462,7 @@ warn_flags = [
'-Wno-tautological-type-limit-compare',
'-Wno-psabi',
'-Wno-gnu-variable-sized-type-not-at-end',
+ '-Wshadow=local',
]
if targetos != 'darwin'
--
2.41.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PULL 0/2] -Wshadow=local patches for 2023-11-13
2023-11-13 9:36 [PULL 0/2] -Wshadow=local patches for 2023-11-13 Markus Armbruster
2023-11-13 9:36 ` [PULL 1/2] block/snapshot: Fix compiler warning with -Wshadow=local Markus Armbruster
2023-11-13 9:36 ` [PULL 2/2] meson: Enable -Wshadow=local Markus Armbruster
@ 2023-11-13 19:27 ` Stefan Hajnoczi
2 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2023-11-13 19:27 UTC (permalink / raw)
To: Markus Armbruster; +Cc: qemu-devel, stefanha
[-- Attachment #1: Type: text/plain, Size: 115 bytes --]
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/8.2 for any user-visible changes.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread