Re: redundant NULL pointer check


Laszlo Ersek
 

On 11/24/20 10:22, wenyi,xie via groups.io wrote:
Hi all,
When removing -Wno-tautological-compare, there's a warning.

MdeModulePkg/Library/FileExplorerLib/FileExplorer.c:850:19: warning: comparison of array 'Info->VolumeLabel' equal to a null pointer is always false [-Wtautological-pointer-compare]
Search "no-tautological-compare" (4904 hits in 1 file)

Since Info is a pointer of struct EFI_FILE_SYSTEM_VOLUME_LABEL, and this struct has only one member VolumeLabel. So Info and Info->VolumeLabel are point to the same place.
So if Info != NULL, is it necessary to check Info->VolumeLabel == NULL again ?
Assuming Info is a valid pointer, Info->VolumeLabel is an array object.

When evaluated, Info->VolumeLabel is converted to the address of its
first element.

The address of the first element of an array object can never be NULL.
And so (Info->VolumeLabel == NULL) will always evaluate to FALSE.

Thanks
Laszlo

Join discuss@edk2.groups.io to automatically receive all group messages.