On 11/11/19 4:30 AM, Bernhard Reutner-Fischer wrote:
On 8 November 2019 17:57:51 CET, Martin Sebor <mse...@gmail.com> wrote:
On 11/6/19 2:06 PM, Martin Sebor wrote:
On 11/6/19 1:39 PM, Jeff Law wrote:
On 11/6/19 1:27 PM, Martin Sebor wrote:
On 11/6/19 11:55 AM, Jeff Law wrote:
On 11/6/19 11:00 AM, Martin Sebor wrote:
The -Wstringop-overflow warnings for single-byte and multi-byte
stores mention the amount of data being stored and the amount of
space remaining in the destination, such as:
warning: writing 4 bytes into a region of size 0 [-Wstringop-overflow=]
123 | *p = 0;
| ~~~^~~
note: destination object declared here
45 | char b[N];
| ^
A warning like this can take some time to analyze. First, the size
of the destination isn't mentioned and may not be easy to tell from
the sources. In the note above, when N's value is the result of
some non-trivial computation, chasing it down may be a small project
in and of itself. Second, it's also not clear why the region size
is zero. It could be because the offset is exactly N, or because
it's negative, or because it's in some range greater than N.
Mentioning both the size of the destination object and the offset
makes the existing messages clearer, are will become essential when
GCC starts diagnosing overflow into allocated buffers (as my
follow-on patch does).
The attached patch enhances -Wstringop-overflow to do this by
letting compute_objsize return the offset to its caller, doing
something similar in get_stridx, and adding a new function to
the strlen pass to issue this enhanced warning (eventually, I'd
like the function to replace the -Wstringop-overflow handler in
builtins.c). With the change, the note above might read something
like:
note: at offset 11 to object ‘b’ with size 8 declared here
45 | char b[N];
| ^
Is "to object" correct? Into? I somehow fund it hard to read as proposed.
I agree. Other messages use "offset from" so let me change it to
that.
Thanks for the suggestion!
Martin