ntfs3: work around false-postive -Wmaybe-uninitialized warnings
PATCH 1/1 ntfs3: work around false-postive -Wmaybe-uninitialized warnings
From: Arnd Bergmann <[email protected]>
gcc sometimes fails to analyse how two local variables in ntfs_write_bh() are initialized, as the initialization happens only in the first pass through the main loop:
fs/ntfs3/fsntfs.c: In function 'ntfs_write_bh':fs/ntfs3/fsntfs.c:1443:17: error: 'fixup' may be used uninitialized [-Werror=maybe-uninitialized]
1443 | __le16 *fixup;
| ^~~~~
fs/ntfs3/fsntfs.c:1443:17: note: 'fixup' was declared here
1443 | __le16 *fixup;
| ^~~~~
fs/ntfs3/fsntfs.c:1487:30: error: 'sample' may be used uninitialized [-Werror=maybe-uninitialized]
1487 | *ptr = sample;
| ~~~~~^~~~~~~~fs/ntfs3/fsntfs.c:1444:16: note: 'sample' was declared here
1444 | __le16 sample;
Initializing the two variables to bogus values shuts up the warning and makes it clear that those cannot be used. I tried rearranging the loop to move the initialization in front of it, but couldn't quite figure it out.
---
I don't know how the set of warnings for ntfs3 was picked, this seems to be based on what W=1 used to do many years ago. -Wmaybe-uninitialized is no longer part of it, and some of the other warnings enabled here are turned on by default now.
--- fs/ntfs3/fsntfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ntfs3/fsntfs.c +2 -2
@@ -1440,8 +1440,8 @@ int ntfs_write_bh(struct ntfs_sb_info *sbi, struct NTFS_RECORD_HEADER *rhdr,u16 fo =le16_to_cpu (rhdr->fix_off);u16 fn =le16_to_cpu (rhdr->fix_num);u32 idx; -__le16 *fixup; -__le16 sample; +__le16 *fixup =NULL ; +__le16 sample =cpu_to_le16 (-1u );if ((fo &1 ) || fo + fn *sizeof (short ) >SECTOR_SIZE || !fn-- || fn *SECTOR_SIZE > bytes) {
Signature · 1 line
2.39.5
Konstantin Komarov
maintainerQuoted 39 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
gcc sometimes fails to analyse how two local variables in
ntfs_write_bh()are initialized, as the initialization happens only in the first pass through the main loop:
fs/ntfs3/fsntfs.c: In function 'ntfs_write_bh':fs/ntfs3/fsntfs.c:1443:17: error: 'fixup' may be used uninitialized [-Werror=maybe-uninitialized]1443 | __le16 *fixup; | ^~~~~ fs/ntfs3/fsntfs.c:1443:17: note: 'fixup' was declared here 1443 | __le16 *fixup; | ^~~~~ fs/ntfs3/fsntfs.c:1487:30: error: 'sample' may be used uninitialized [-Werror=maybe-uninitialized] 1487 | *ptr = sample; | ~~~~~^~~~~~~~
fs/ntfs3/fsntfs.c:1444:16: note: 'sample' was declared here
1444 |__le16sample;Initializing the two variables to bogus values shuts up the warning and makes it clear that those cannot be used. I tried rearranging the loop to move the initialization in front of it, but couldn't quite figure it out.
Fixes 48d9b57b169f ("fs/ntfs3: add a subset of W=1 warnings for stricter checks")Signed-off-by Arnd Bergmann <[email protected]>---
I don't know how the set of warnings for ntfs3 was picked, this seems to be based on what W=1 used to do many years ago. -Wmaybe-uninitialized is no longer part of it, and some of the other warnings enabled here are turned on by default now.--- fs/ntfs3/fsntfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/ntfs3/fsntfs.c +0
-0
fs/ntfs3/fsntfs.c int ntfs_write_bh(struct ntfs_sb_info *sbi, struct NTFS_RECORD_HEADER *rhdr, · line 1447
Quoted 10 lines
fs/ntfs3/fsntfs.c +2
-2@@ -1440,8 +1440,8 @@ int ntfs_write_bh(struct ntfs_sb_info *sbi, struct NTFS_RECORD_HEADER *rhdr,u16 fo =le16_to_cpu (rhdr->fix_off);u16 fn =le16_to_cpu (rhdr->fix_num);u32 idx; -__le16 *fixup; -__le16 sample; +__le16 *fixup =NULL ; +__le16 sample =cpu_to_le16 (-1u );if ((fo &1 ) || fo + fn *sizeof (short ) >SECTOR_SIZE || !fn-- || fn *SECTOR_SIZE > bytes) {
Hello,
Thanks for the patch, applied.
Regards,
Konstantin