diff options
author | Tim Lange <mail@tim-lange.me> | 2024-05-09 13:09:26 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2024-05-09 13:09:26 -0400 |
commit | e0c52905f666e3d23881f82dbf39466a24f009f4 (patch) | |
tree | aea75b6f621124e0235d636046b042f090a35a4b | |
parent | ccf8d3e3d26c6ba3d5e11fffeed8d64018e9c060 (diff) | |
download | gcc-e0c52905f666e3d23881f82dbf39466a24f009f4.zip gcc-e0c52905f666e3d23881f82dbf39466a24f009f4.tar.gz gcc-e0c52905f666e3d23881f82dbf39466a24f009f4.tar.bz2 |
testsuite: Add more allocation size tests for conjured svalues [PR110014]
This patch adds the reproducers reported in PR 110014 as test cases. The
false positives in those cases are already fixed with PR 109577.
2023-06-09 Tim Lange <mail@tim-lange.me>
PR analyzer/110014
gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/realloc-pr110014.c: New tests.
(cherry picked from commit r14-1685-g39adc5eebd61fd276f3f1ef9d7228756a35bd0cb)
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
-rw-r--r-- | gcc/testsuite/gcc.dg/analyzer/realloc-pr110014.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/analyzer/realloc-pr110014.c b/gcc/testsuite/gcc.dg/analyzer/realloc-pr110014.c new file mode 100644 index 0000000..d76b878 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/realloc-pr110014.c @@ -0,0 +1,25 @@ +void *realloc (void *, unsigned long) + __attribute__((__nothrow__, __leaf__)) + __attribute__((__warn_unused_result__)) __attribute__((__alloc_size__ (2))); + +long * +slurp (long *buffer, unsigned long file_size) +{ + unsigned long cc; + if (!__builtin_add_overflow (file_size - file_size % sizeof (long), + 2 * sizeof (long), &cc)) + buffer = realloc (buffer, cc); + return buffer; +} + +long * +slurp1 (long *buffer, unsigned long file_size) +{ + return realloc (buffer, file_size - file_size % sizeof (long)); +} + +long * +slurp2 (long *buffer, unsigned long file_size) +{ + return realloc (buffer, (file_size / sizeof (long)) * sizeof (long)); +} |