Re: [PATCH] btrfs: Turn an 'else if' into an 'else' in btrfs_uuid_tree_add

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Mar 07, 2019 at 09:35:15AM -0700, Nathan Chancellor wrote:
> When building with -Wsometimes-uninitialized, Clang warns:
> 
> fs/btrfs/uuid-tree.c:129:13: warning: variable 'eb' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
> fs/btrfs/uuid-tree.c:129:13: warning: variable 'offset' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
> 
> Clang can't tell that all cases are covered with this final else if.

The chain of conditions is

if (ret >= 0)
else if (ret == -EEXIST)
else if (ret < 0)

I'd think that compiler should be able to somehow represent the coverage
of the ranges and report if it's not complete and leading to some
uninitialized variables.

What if the last condition is 'ret < -EINVAL' obscuring the numerical
value, it'd be easy to miss that there are 20 unhandled values. In such
case the final 'else' would be the right thing to do.

Anyway, I'll apply the patch because it makes the code easier to follow.
Thanks.



[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux