[Bug preprocessor/77672] wrong rich location in warning: writing a terminating nul past the end

2019-08-16 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77672

Martin Sebor  changed:

   What|Removed |Added

 Status|WAITING |RESOLVED
  Known to work||7.1.0
 Resolution|--- |FIXED
  Known to fail||7.0

--- Comment #9 from Martin Sebor  ---
The output looks good now and has since 7.1 so we can resolve this bug.

[Bug preprocessor/77672] wrong rich location in warning: writing a terminating nul past the end

2019-08-12 Thread egallager at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77672

Eric Gallager  changed:

   What|Removed |Added

 Status|ASSIGNED|WAITING
 CC||egallager at gcc dot gnu.org

--- Comment #8 from Eric Gallager  ---
(In reply to Martin Liška from comment #7)
> David: Can the bug be marked as resolved?

WAITING on a reply

[Bug preprocessor/77672] wrong rich location in warning: writing a terminating nul past the end

2018-11-19 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77672

Martin Liška  changed:

   What|Removed |Added

 CC||marxin at gcc dot gnu.org

--- Comment #7 from Martin Liška  ---
David: Can the bug be marked as resolved?

[Bug preprocessor/77672] wrong rich location in warning: writing a terminating nul past the end

2016-09-23 Thread dmalcolm at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77672

--- Comment #6 from David Malcolm  ---
Author: dmalcolm
Date: Fri Sep 23 16:55:27 2016
New Revision: 240442

URL: https://gcc.gnu.org/viewcvs?rev=240442&root=gcc&view=rev
Log:
Fix gcc.dg/tree-ssa/builtin-sprintf-warn-4.c

gcc/testsuite/ChangeLog
PR preprocessor/77672
* gcc.dg/tree-ssa/builtin-sprintf-warn-4.c (test): Update
expected multiline output from first warning to reflect change
in r240434.


Modified:
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-4.c

[Bug preprocessor/77672] wrong rich location in warning: writing a terminating nul past the end

2016-09-23 Thread dmalcolm at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77672

--- Comment #5 from David Malcolm  ---
BTW, if you do have a need to send a "print the whole string" request via class
substring_loc, that could be handled by passing in INT_MAX as the idx values,
which will lead to a failure.  (we could make it handle -1 similarly, but
input.c:get_source_location_for_substring currently only checks the upper
bound; it doesn't yet check > 0, but that would be trivial).

[Bug preprocessor/77672] wrong rich location in warning: writing a terminating nul past the end

2016-09-23 Thread dmalcolm at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77672

--- Comment #4 from David Malcolm  ---
(In reply to Martin Sebor from comment #2)
> I think the general improvement I'm suggesting is to be able to put the
> tilde(s) under or point the caret at any character of the format string,
> including either of the two quotes.

If desired, you can use make_location to construct a location_t for such
situations... though I'm not sure that it makes sense to do so for all of the
different combinations.  I've tried to make class substring_loc provide the API
needed for the common case.

> It's already possible to underscore the whole format string and point the
> caret at any character within in, including the first quote, so it seems
> natural to also point the caret at the last quote.

r240434 updates things so that substring_loc::get_location uses the final quote
for the location of the NUL-terminator character for STRING_CSTs from the C
frontend, so that if that character's index is passed as one of the indices to
substring_loc's constructor, it will handle that (previously, doing so would
lead to substring_loc::get_location, leading to format_warning using the whole
string range, with both start and end quotes).

The output for the test case is now:

$ ./xgcc -B. -c v.c -Wall
v.c: In function ‘f’:
v.c:6:19: warning: writing format character ‘!’ at offset 3 past the end of the
destination [-Wformat-length=]
   sprintf (d, "%-s!", "abc");
   ^
v.c:6:3: note: format output 5 bytes into a destination of size 3
   sprintf (d, "%-s!", "abc");
   ^~
v.c: In function ‘g’:
v.c:10:18: warning: writing a terminating nul past the end of the destination
[-Wformat-length=]
   sprintf (d, "%-s", "abc");
~~^~
v.c:10:3: note: format output 4 bytes into a destination of size 3
   sprintf (d, "%-s", "abc");
   ^

Note how in the warning for g it has underlined from the first char through to
the close-quote, with the caret on the s.  This is with:

(gdb) p fmt_loc
$1 = (const substring_loc &) @0x7fffda90: {m_fmt_string_loc = 2147483655,
m_string_type = , 
  m_caret_idx = 2, m_start_idx = 0, m_end_idx = 3}

so it is faithfully printing the idx values it's been provided with by the
diagnostic code.

[Bug preprocessor/77672] wrong rich location in warning: writing a terminating nul past the end

2016-09-23 Thread dmalcolm at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77672

--- Comment #3 from David Malcolm  ---
Author: dmalcolm
Date: Fri Sep 23 14:14:52 2016
New Revision: 240434

URL: https://gcc.gnu.org/viewcvs?rev=240434&root=gcc&view=rev
Log:
Provide location information for terminator characters (PR preprocessor/77672)

substring_loc::get_location currently fails for the final terminator
character in a STRING_CST from the C frontend, so that format_warning_va
falls back to using the location of the string as a whole.

This patch tweaks things [1] so that we use the final closing quote
as the location of the terminator character, as requested in
PR preprocessor/77672.

[1] specifically, cpp_interpret_string_1.

gcc/ChangeLog:
PR preprocessor/77672
* input.c (selftest::test_lexer_string_locations_simple): Update
test to expect location information of the terminator character
at the location of the final closing quote.
(selftest::test_lexer_string_locations_hex): Likewise.
(selftest::test_lexer_string_locations_oct): Likewise.
(selftest::test_lexer_string_locations_letter_escape_1): Likewise.
(selftest::test_lexer_string_locations_letter_escape_2): Likewise.
(selftest::test_lexer_string_locations_ucn4): Likewise.
(selftest::test_lexer_string_locations_ucn8): Likewise.
(selftest::test_lexer_string_locations_u8): Likewise.
(selftest::test_lexer_string_locations_utf8_source): Likewise.
(selftest::test_lexer_string_locations_concatenation_1): Likewise.
(selftest::test_lexer_string_locations_concatenation_2): Likewise.
(selftest::test_lexer_string_locations_concatenation_3): Likewise.
(selftest::test_lexer_string_locations_macro): Likewise.
(selftest::test_lexer_string_locations_long_line): Likewise.

gcc/testsuite/ChangeLog:
PR preprocessor/77672
* gcc.dg/plugin/diagnostic-test-string-literals-1.c
(test_terminator_location): New function.

libcpp/ChangeLog:
PR preprocessor/77672
* charset.c (cpp_interpret_string_1): Add a source_range for the
NUL-terminator, using the location of the trailing quote of the
final string.


Modified:
trunk/gcc/ChangeLog
trunk/gcc/input.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-1.c
trunk/libcpp/ChangeLog
trunk/libcpp/charset.c

[Bug preprocessor/77672] wrong rich location in warning: writing a terminating nul past the end

2016-09-22 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77672

--- Comment #2 from Martin Sebor  ---
I think the general improvement I'm suggesting is to be able to put the
tilde(s) under or point the caret at any character of the format string,
including either of the two quotes.

It's already possible to underscore the whole format string and point the caret
at any character within in, including the first quote, so it seems natural to
also point the caret at the last quote.