]> git.ipfire.org Git - thirdparty/gcc.git/commit
analyzer: fix offsets in has_null_terminator [PR112811]
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 18 Jan 2024 17:11:57 +0000 (12:11 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Thu, 18 Jan 2024 17:11:57 +0000 (12:11 -0500)
commit84096e665c5f7d7ffb07f18a5fd5e804a94b237b
tree6715a673b8a6665564f487beb49765a419cd63b5
parente254d1224df306a07f3b0b572af2582f509b7d67
analyzer: fix offsets in has_null_terminator [PR112811]

PR analyzer/112811 reports an ICE attempting to determine whether a
string is null-terminated.

The root cause is confusion in the code about whether byte offsets are
relative to the start of the base region, or relative to the bound
fragment within the the region.

This patch rewrites the code to enforce a clearer separation between
the kinds of offset, fixing the ICE, and adds logging to help track
down future issues in this area of the code.

gcc/analyzer/ChangeLog:
PR analyzer/112811
* region-model.cc (fragment::dump_to_pp): New.
(fragment::has_null_terminator): Convert to...
(svalue_byte_range_has_null_terminator_1): ...this new function,
updating to use a byte_range relative to the start of the svalue.
(svalue_byte_range_has_null_terminator): New.
(fragment::string_cst_has_null_terminator): Convert to...
(string_cst_has_null_terminator): ...this, updating to use a
byte_range relative to the start of the svalue.
(iterable_cluster::dump_to_pp): New.
(region_model::scan_for_null_terminator): Add logging, moving body
to...
(region_model::scan_for_null_terminator_1): ...this new function,
adding more logging, and updating to use
svalue_byte_range_has_null_terminator.
* region-model.h (region_model::scan_for_null_terminator_1): New
decl.

gcc/testsuite/ChangeLog:
PR analyzer/112811
* c-c++-common/analyzer/strlen-pr112811.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/analyzer/region-model.cc
gcc/analyzer/region-model.h
gcc/testsuite/c-c++-common/analyzer/strlen-pr112811.c [new file with mode: 0644]