Re: [PATCH 1/3] btrfs-progs: use btrfs_key for btrfs_check_node() and btrfs_check_leaf()

David Sterba
2021-09-06T14:46:32Z

On Sat, Sep 04, 2021 at 01:06:10PM +0800, Qu Wenruo wrote:
> >> -            btrfs_disk_key_to_cpu(&cpukey, parent_key);
> >> +            memcpy(&key, parent_key, sizeof(struct btrfs_key));
> >>           else
> >> -            btrfs_item_key_to_cpu(buf, &cpukey, 0);
> >> +            btrfs_item_key_to_cpu(buf, &key, 0);
> >> -        btrfs_add_corrupt_extent_record(fs_info, &cpukey,
> >> +        btrfs_add_corrupt_extent_record(fs_info, &key,
> >>                           buf->start, buf->len, 0);
> >>       }
> >>       return ret;
> >> @@ -705,22 +710,21 @@ fail:
> >>   static int noinline check_block(struct btrfs_fs_info *fs_info,
> >>                   struct btrfs_path *path, int level)
> >>   {
> >> -    struct btrfs_disk_key key;
> >> -    struct btrfs_disk_key *key_ptr = NULL;
> >> -    struct extent_buffer *parent;
> >> +    struct btrfs_key key;
> >> +    struct btrfs_key *parent_key_ptr;
> >
> > This is the cause of fsck tests failure.
> >
> > @parent_key_ptr is not initialized, but I'm also wondering why compiler
> > is not slapping a big warning onto my face.
>
> Not sure why but neither clang 12.0.1 nor 11.1.0 gives me any warning on
> the uninitialized pointer, even if -Wuninitialized is specified.
>
> Any idea/suggestion to detect such uninitialized pointer?

My best guess is that the stack variables are implicitly initialized to
zero and there are checks inside the functions, and this somehow tells
the compiler not to report it as uninitialized. I'm running 11.1.1 and
don't see any warning with our without -Wuninitialized.