https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104789

--- Comment #6 from RĂ©mi Verschelde <rverschelde at gmail dot com> ---
Indeed if the warning was reworded to make it clear that it's a risk and not a
certainty would solve this.

Both the reduced test case and the original code are both risky: `components`
is an `uint32_t` that is set to either 1 or 3, so in the context of that code
`header_bytes` would never exceed 8.

But if this was changed to anything higher than 3 then yes, there would be a
buffer overflow. If this is what this warning aims to warn about (the risk of
buffer overflow and not the certainty of one), then there's probably no false
positive.

Adding:
```
if (components > 3) {
        return 0;
}
```
to the reduced testcase does prevent the warning.

On the other hand, the same kind of check doesn't seem to solve the warning in
the original Godot case, so you're right about the reduced testcase being too
reduced. I'll dig further and see if I can make a better testcase, or
understand why a check on `components` (or even `header_bytes > 7`) isn't
sufficient in Godot.

Reply via email to