Skip to contentSkip to conversation

cmds-restore.c:182:20: warning: array subscript is above array bounds [-Warray-bounds]

btrfs-progs Duncan 2 participants 3 messages Nov 9, 2014 – Nov 19, 2014 Btrfs file system

lore
Share & tools
lore

Duncan

author
#0 lore raw

Updating to the latest live-git btrfs-progs (on v3.17.1 tag), I chanced across this (gentoo) warning, pointing to a gcc warning believed to be severe:

* QA Notice: Package triggers severe warnings which indicate that it
* may exhibit random runtime failures.
* cmds-restore.c:182:20: warning: array subscript is above array bounds
[-Warray-bounds]

* Please do not file a Gentoo bug and instead report the above QA
* issues directly to the upstream developers of this software.
* Homepage: https://btrfs.wiki.kernel.org

A bit more context:

cmds-restore.c: In function 'next_leaf':
cmds-restore.c:182:20: warning: array subscript is above array bounds [-Warray-bounds]

  slot = path->slots[level] + 1;
                    ^

Not being a coder I've no idea if it's a false-alarm or not, and I generally ignore these QA warnings since I've little hope of providing much more than the basic information or help, but since I'm already active here I thought I'd post it and see what happens.

FWIW, gentoo/~amd64, gcc-4.8.3.

Full build log available if needed altho I expect it should be easy enough to trace without. Note that I normally build with MAKEOPTS="-j10 -l8" so if log serialization is desired, please request a -j1 build log.

Signature · 3 lines
Duncan - List replies preferred.   No HTML msgs.
"Every nonfree program has a lord, a master --
and if you use the program, he is your master."  Richard Stallman
#1 lore raw
Quoted 7 lines · Duncan

A bit more context:

cmds-restore.c: In function 'next_leaf':
cmds-restore.c:182:20: warning: array subscript is above array bounds [-Warray-bounds]

  slot = path->slots[level] + 1;
                    ^

Thanks. We've seen that before and were not able to find why the compiler thinks it could overflow, see the dicussion here:

http://www.mail-archive.com/linux-btrfs%40vger.kernel.org/msg34338.html

I'll probably merge Christian's patch so the warning goes away.

author
#2 lore raw

David Sterba posted on Tue, 18 Nov 2014 18:23:23 +0100 as excerpted:

Quoted 9 lines · Duncan
Quoted 7 lines

A bit more context:

cmds-restore.c: In function 'next_leaf':
cmds-restore.c:182:20: warning: array subscript is above array bounds [-Warray-bounds]

  slot = path->slots[level] + 1;
                    ^
Quoted 6 lines

Thanks. We've seen that before and were not able to find why the compiler thinks it could overflow, see the dicussion here:

http://www.mail-archive.com/linux-btrfs%40vger.kernel.org/msg34338.html

I'll probably merge Christian's patch so the warning goes away.

Thanks. I don't claim to be a coder but I surely can't see where/how the code as written could go out of array bounds either.

The bit the worries me is that -Warray-bounds says it warns where subscripts are *ALWAYS* out of bounds. Couple that with the "unintuitive" optimizations that I've seen gcc reported as doing from time to time, and admittedly not understanding all the implications involved, and "optimized to always out of bounds" seems uncomfortably within the realm of possibility, given the warning.

The next step if I were to go from there would be to CC or file a bug with the gentoo QA team, who after all consider this gcc warning serious enough to point it out in (colored!) QA warnings before a package is installed. As such, perhaps they know enough about gcc optimizations specific to this warning to explain what gcc's actually warning about here, since "upstream" can't see a problem and neither can I. I just gotta decide whether it's worth bothering them with or not.

Signature · 3 lines
Duncan - List replies preferred.   No HTML msgs.
"Every nonfree program has a lord, a master --
and if you use the program, he is your master."  Richard Stallman