sarif-replay: fix off-by-one in handling of "endColumn" (§3.30.8) [PR118792]

gcc/ChangeLog:
	PR sarif-replay/118792
	* libsarifreplay.cc (sarif_replayer::handle_region_object): Fix
	off-by-one in handling of endColumn property so that the code
	matches the comment and the SARIF spec (§3.30.8).

gcc/testsuite/ChangeLog:
	PR sarif-replay/118792
	* sarif-replay.dg/2.1.0-valid/error-with-note.sarif: Update
	expected output to reflect fix to off-by-one error in handling of
	"endColumn" property.
	* sarif-replay.dg/2.1.0-valid/malloc-vs-local-4.c.sarif: Likewise.
	* sarif-replay.dg/2.1.0-valid/signal-1.c.moved.sarif: Likewise.
	* sarif-replay.dg/2.1.0-valid/signal-1.c.sarif: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
This commit is contained in:
David Malcolm 2025-02-11 08:54:15 -05:00
parent 0f8fd6b336
commit e8c5013b6b
5 changed files with 29 additions and 29 deletions

View file

@ -1739,7 +1739,7 @@ handle_region_object (const json::object &region_obj,
/* SARIF's endColumn is 1 beyond the final column in the region,
whereas GCC's end columns are inclusive. */
end = m_output_mgr.new_location_from_file_line_column
(file, end_line, end_column_jnum->get ());
(file, end_line, end_column_jnum->get () - 1);
}
else
{

View file

@ -26,12 +26,12 @@
/* { dg-begin-multiline-output "" }
/this/does/not/exist/test.bas:2:8: error: 'GOTO' is considered harmful
2 | GOTO label
| ^~~~~~~~~~
| ^~~~~~~~~~
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
/this/does/not/exist/test.bas:1:1: note: this is the target of the 'GOTO'
1 | label: PRINT "hello world!"
| ^~~~~~
| ^~~~~
{ dg-end-multiline-output "" } */
// TODO: trailing [error]

View file

@ -339,37 +339,37 @@
In function 'callee_1':
/not/a/real/path/malloc-vs-local-4.c:5:3: warning: dereference of possibly-NULL ptr [-Wanalyzer-possible-null-dereference]
5 | *ptr = 42;
| ^~~~~~~~~~
| ^~~~~~~~~
'test_1': events 1-5
|
| 8 | int test_1 (int i, int flag)
| | ^~~~~~~
| | ^~~~~~
| | |
| | (1) entry to test_1
|......
| 12 | if (flag)
| | ~~
| | ~
| | |
| | (2) following true branch (when flag != 0)...
| 13 | ptr = (int *)malloc (sizeof (int));
| | ~~~~~~~~~~~~~~~~~~~~~~
| | ~~~~~~~~~~~~~~~~~~~~~
| | |
| | (3) ...to here
| | (4) this call could return NULL
| 14 | callee_1 (ptr);
| | ~~~~~~~~~~~~~~~
| | ~~~~~~~~~~~~~~
| | |
| | (5) calling callee_1 from test_1
|
+--> 'callee_1': events 6-7
|
| 3 | void __attribute__((noinline)) callee_1 (int *ptr)
| | ^~~~~~~~~
| | ^~~~~~~~
| | |
| | (6) entry to callee_1
| 4 | {
| 5 | *ptr = 42;
| | ~~~~~~~~~~
| | ~~~~~~~~~
| | |
| | (7) ptr could be NULL: unchecked value from (4)
|
@ -378,24 +378,24 @@ In function 'callee_1':
In function 'test_2':
/not/a/real/path/malloc-vs-local-4.c:38:7: warning: double-free of ptr [-Wanalyzer-double-free]
38 | free (ptr);
| ^~~~~~~~~~~
| ^~~~~~~~~~
'test_2': events 1-5
34 | if (!flag)
| ^~
| ^
| |
| (1) following true branch (when flag == 0)...
35 | {
36 | void *ptr = malloc (16);
| ~~~~~~~~~~~~
| ~~~~~~~~~~~
| |
| (2) ...to here
| (3) allocated here
37 | free (ptr);
| ~~~~~~~~~~~
| ~~~~~~~~~~
| |
| (4) first free here
38 | free (ptr);
| ~~~~~~~~~~~
| ~~~~~~~~~~
| |
| (5) second free here; first free was at (4)
{ dg-end-multiline-output "" } */

View file

@ -170,16 +170,16 @@
In function 'custom_logger':
signal-1.c:13:3: warning: call to fprintf from within signal handler [-Wanalyzer-unsafe-call-within-signal-handler]
13 | fprintf(stderr, "LOG: %s", msg);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'main': events 1-2
|
| 21 | int main(int argc, const char *argv)
| | ^~~~~
| | ^~~~
| | |
| | (1) entry to main
|......
| 25 | signal(SIGINT, handler);
| | ~~~~~~~~~~~~~~~~~~~~~~~~
| | ~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | (2) registering handler as signal handler
|
@ -191,24 +191,24 @@ signal-1.c:13:3: warning: call to fprintf from within signal handler [-Wan
+--> 'handler': events 4-5
|
| 16 | static void handler(int signum)
| | ^~~~~~~~
| | ^~~~~~~
| | |
| | (4) entry to handler
| 17 | {
| 18 | custom_logger("got signal");
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | (5) calling custom_logger from handler
|
+--> 'custom_logger': events 6-7
|
| 11 | void custom_logger(const char *msg)
| | ^~~~~~~~~~~~~~
| | ^~~~~~~~~~~~~
| | |
| | (6) entry to custom_logger
| 12 | {
| 13 | fprintf(stderr, "LOG: %s", msg);
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | (7) call to fprintf from within signal handler
|

View file

@ -168,16 +168,16 @@
In function 'custom_logger':
../../src/gcc/testsuite/gcc.dg/analyzer/signal-1.c:13:3: warning: call to fprintf from within signal handler [-Wanalyzer-unsafe-call-within-signal-handler]
13 | fprintf(stderr, "LOG: %s", msg);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'main': events 1-2
|
| 21 | int main(int argc, const char *argv)
| | ^~~~~
| | ^~~~
| | |
| | (1) entry to main
|......
| 25 | signal(SIGINT, handler);
| | ~~~~~~~~~~~~~~~~~~~~~~~~
| | ~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | (2) registering handler as signal handler
|
@ -189,24 +189,24 @@ In function 'custom_logger':
+--> 'handler': events 4-5
|
| 16 | static void handler(int signum)
| | ^~~~~~~~
| | ^~~~~~~
| | |
| | (4) entry to handler
| 17 | {
| 18 | custom_logger("got signal");
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | (5) calling custom_logger from handler
|
+--> 'custom_logger': events 6-7
|
| 11 | void custom_logger(const char *msg)
| | ^~~~~~~~~~~~~~
| | ^~~~~~~~~~~~~
| | |
| | (6) entry to custom_logger
| 12 | {
| 13 | fprintf(stderr, "LOG: %s", msg);
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | (7) call to fprintf from within signal handler
|