lkml.org 
[lkml]   [2020]   [Apr]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 10/15] hpfs: avoid gcc-10 zero-length-bounds warning
Date
gcc-10 now warns about accessing members of a zero-length array
field:

fs/hpfs/anode.c: In function 'hpfs_add_sector_to_btree':
fs/hpfs/anode.c:209:27: error: array subscript 0 is outside the bounds of an interior zero-length array 'struct bplus_internal_node[0]' [-Werror=zero-length-bounds]
209 | anode->btree.u.internal[0].down = cpu_to_le32(a);
| ~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from fs/hpfs/hpfs_fn.h:26,
from fs/hpfs/anode.c:10:
fs/hpfs/hpfs.h:411:32: note: while referencing 'internal'
411 | struct bplus_internal_node internal[0]; /* (internal) 2-word entries giving
| ^~~~~~~~

It would be nice to make it a flexible-array member, but that is not
possible inside of a union, so work around the warnings by adding
a temporary pointer that hides the problem.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
fs/hpfs/anode.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/hpfs/anode.c b/fs/hpfs/anode.c
index c14c9a035ee0..55788ca7969f 100644
--- a/fs/hpfs/anode.c
+++ b/fs/hpfs/anode.c
@@ -200,14 +200,17 @@ secno hpfs_add_sector_to_btree(struct super_block *s, secno node, int fnod, unsi
brelse(bh);
a = na;
if ((new_anode = hpfs_alloc_anode(s, a, &na, &bh))) {
+ struct bplus_internal_node *internal;
+
anode = new_anode;
/*anode->up = cpu_to_le32(up != -1 ? up : ra);*/
anode->btree.flags |= BP_internal;
anode->btree.n_used_nodes = 1;
anode->btree.n_free_nodes = 59;
anode->btree.first_free = cpu_to_le16(16);
- anode->btree.u.internal[0].down = cpu_to_le32(a);
- anode->btree.u.internal[0].file_secno = cpu_to_le32(-1);
+ internal = anode->btree.u.internal;
+ internal->down = cpu_to_le32(a);
+ internal->file_secno = cpu_to_le32(-1);
mark_buffer_dirty(bh);
brelse(bh);
if ((anode = hpfs_map_anode(s, a, &bh))) {
--
2.26.0
\
 
 \ /
  Last update: 2020-04-30 23:33    [W:0.185 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site