grub/grub-core/fs
Michael Chang 68006d1732 zfs: Fix gcc10 error -Werror=zero-length-bounds
We bumped into the build error while testing gcc-10 pre-release.

In file included from ../../include/grub/file.h:22,
		from ../../grub-core/fs/zfs/zfs.c:34:
../../grub-core/fs/zfs/zfs.c: In function 'zap_leaf_lookup':
../../grub-core/fs/zfs/zfs.c:2263:44: error: array subscript '<unknown>' is outside the bounds of an interior zero-length array 'grub_uint16_t[0]' {aka 'short unsigned int[0]'} [-Werror=zero-length-bounds]
2263 |   for (chunk = grub_zfs_to_cpu16 (l->l_hash[LEAF_HASH (blksft, h, l)], endian);
../../include/grub/types.h:241:48: note: in definition of macro 'grub_le_to_cpu16'
 241 | # define grub_le_to_cpu16(x) ((grub_uint16_t) (x))
     |                                                ^
../../grub-core/fs/zfs/zfs.c:2263:16: note: in expansion of macro 'grub_zfs_to_cpu16'
2263 |   for (chunk = grub_zfs_to_cpu16 (l->l_hash[LEAF_HASH (blksft, h, l)], endian);
     |                ^~~~~~~~~~~~~~~~~
In file included from ../../grub-core/fs/zfs/zfs.c:48:
../../include/grub/zfs/zap_leaf.h:72:16: note: while referencing 'l_hash'
  72 |  grub_uint16_t l_hash[0];
     |                ^~~~~~

Here I'd like to quote from the gcc document [1] which seems best to
explain what is going on here.

"Although the size of a zero-length array is zero, an array member of
this kind may increase the size of the enclosing type as a result of
tail padding. The offset of a zero-length array member from the
beginning of the enclosing structure is the same as the offset of an
array with one or more elements of the same type. The alignment of a
zero-length array is the same as the alignment of its elements.

Declaring zero-length arrays in other contexts, including as interior
members of structure objects or as non-member objects, is discouraged.
Accessing elements of zero-length arrays declared in such contexts is
undefined and may be diagnosed."

The l_hash[0] is apparnetly an interior member to the enclosed structure
while l_entries[0] is the trailing member. And the offending code tries
to access members in l_hash[0] array that triggers the diagnose.

Given that the l_entries[0] is used to get proper alignment to access
leaf chunks, we can accomplish the same thing through the ALIGN_UP macro
thus eliminating l_entries[0] from the structure. In this way we can
pacify the warning as l_hash[0] now becomes the last member to the
enclosed structure.

[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2020-03-31 12:17:03 +02:00
..
zfs zfs: Fix gcc10 error -Werror=zero-length-bounds 2020-03-31 12:17:03 +02:00
affs.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
afs.c Leverage BFS implementation to read AFS. 2011-10-30 16:10:18 +01:00
archelp.c archelp: Never pass NULL as mtime. 2015-07-27 13:19:02 +02:00
bfs.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
btrfs.c btrfs: Add support for new RAID1C34 profiles 2019-12-06 20:38:01 +01:00
cbfs.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
cpio.c Add gcc_struct to all packed structures when compiling with mingw. 2013-12-15 14:14:30 +01:00
cpio_be.c Add gcc_struct to all packed structures when compiling with mingw. 2013-12-15 14:14:30 +01:00
cpio_common.c cpio: Disable gcc9 -Waddress-of-packed-member 2019-04-23 11:37:08 +02:00
exfat.c exfat reader 2011-04-11 18:13:00 +02:00
ext2.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
f2fs.c f2fs: Disable gcc9 -Waddress-of-packed-member 2019-06-03 11:18:31 +02:00
fat.c fat: Support file modification times 2020-03-10 21:52:07 +01:00
fshelp.c fshelp: Add handling of "." and ".." and grub_fshelp_find_file_lookup. 2015-07-27 12:45:35 +02:00
hfs.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
hfsplus.c hfsplus: Fix gcc9 error with -Waddress-of-packed-member 2019-04-23 11:37:08 +02:00
hfspluscomp.c Make grub_zlib_decompress handle incomplete chunks. 2013-12-18 23:39:49 +01:00
iso9660.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
jfs.c jfs: Disable gcc9 -Waddress-of-packed-member 2019-04-23 11:37:08 +02:00
minix.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
minix2.c Split minix.mod into minix.mod and minix2.mod. 2010-09-08 19:13:48 +02:00
minix2_be.c Handle big-endian minixfs (fixes minixfs tests on bigendian). 2012-04-01 21:35:18 +02:00
minix3.c minix3fs support 2011-04-11 08:16:13 +02:00
minix3_be.c Handle big-endian minixfs (fixes minixfs tests on bigendian). 2012-04-01 21:35:18 +02:00
minix_be.c Handle big-endian minixfs (fixes minixfs tests on bigendian). 2012-04-01 21:35:18 +02:00
newc.c Add gcc_struct to all packed structures when compiling with mingw. 2013-12-15 14:14:30 +01:00
nilfs2.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
ntfs.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
ntfscomp.c Fix warnings when compiling with -O3 2016-02-17 17:56:41 +01:00
odc.c Add gcc_struct to all packed structures when compiling with mingw. 2013-12-15 14:14:30 +01:00
proc.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
reiserfs.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
romfs.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
sfs.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
squash4.c squash4: Fix an uninitialized variable 2020-01-28 21:22:01 +01:00
tar.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
udf.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
ufs.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00
ufs2.c automake commit without merge history 2010-05-06 11:34:04 +05:30
ufs_be.c Support big-endian UFS1. 2012-12-08 20:56:58 +01:00
xfs.c Change fs functions to add fs_ prefix 2019-04-09 10:03:29 +10:00