Message ID | 20200507121129.29760-2-philmd@redhat.com |
---|---|
State | New |
Headers | show |
Series | block/block-copy: Fix uninitialized variable in block_copy_task_entry | expand |
On 5/7/20 7:11 AM, Philippe Mathieu-Daudé wrote: > Fix when building with -Os: > > CC block/block-copy.o > block/block-copy.c: In function ‘block_copy_task_entry’: > block/block-copy.c:428:38: error: ‘error_is_read’ may be used uninitialized in this function [-Werror=maybe-uninitialized] > 428 | t->call_state->error_is_read = error_is_read; > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ > Looks like -Os triggered different inlining of block_copy_do_copy(). I confirm that block_copy_do_copy does NOT initialize error_is_read except when returning < 0, but similarly block_copy_task_entry() does not read error_is_read except in the same setups. So it looks like no actual bug was triggered, but we can definitely aid the compiler's analysis by initializing. > Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> > --- > block/block-copy.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Reviewed-by: Eric Blake <eblake@redhat.com>
diff --git a/block/block-copy.c b/block/block-copy.c index 03500680f7..83e16c89d9 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -418,7 +418,7 @@ out: static coroutine_fn int block_copy_task_entry(AioTask *task) { BlockCopyTask *t = container_of(task, BlockCopyTask, task); - bool error_is_read; + bool error_is_read = false; int ret; ret = block_copy_do_copy(t->s, t->offset, t->bytes, t->zeroes,
Fix when building with -Os: CC block/block-copy.o block/block-copy.c: In function ‘block_copy_task_entry’: block/block-copy.c:428:38: error: ‘error_is_read’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 428 | t->call_state->error_is_read = error_is_read; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> --- block/block-copy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)