aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@gotplt.org>2022-11-04 08:42:57 -0400
committerSiddhesh Poyarekar <siddhesh@gotplt.org>2022-11-22 17:54:06 -0500
commite5cfb9cac1d7aba9a8ea73bfe7922cfaff9d61f3 (patch)
tree082f70249752af626fa1e104f2547d9fdd1845b8 /libcpp
parentec7c796de020cb5cd955aa5b26c92b1da49d6076 (diff)
downloadgcc-e5cfb9cac1d7aba9a8ea73bfe7922cfaff9d61f3.zip
gcc-e5cfb9cac1d7aba9a8ea73bfe7922cfaff9d61f3.tar.gz
gcc-e5cfb9cac1d7aba9a8ea73bfe7922cfaff9d61f3.tar.bz2
tree-object-size: Support strndup and strdup
Use string length of input to strdup to determine the usable size of the resulting object. Avoid doing the same for strndup since there's a chance that the input may be too large, resulting in an unnecessary overhead or worse, the input may not be NULL terminated, resulting in a crash where there would otherwise have been none. gcc/ChangeLog: * tree-object-size.cc (todo): New variable. (object_sizes_execute): Use it. (strdup_object_size): New function. (call_object_size): Use it. gcc/testsuite/ChangeLog: * gcc.dg/builtin-dynamic-object-size-0.c (test_strdup, test_strndup, test_strdup_min, test_strndup_min): New tests. (main): Call them. * gcc.dg/builtin-dynamic-object-size-1.c: Silence overread warnings. * gcc.dg/builtin-dynamic-object-size-2.c: Likewise. * gcc.dg/builtin-dynamic-object-size-3.c: Likewise. * gcc.dg/builtin-dynamic-object-size-4.c: Likewise. * gcc.dg/builtin-object-size-1.c: Silence overread warnings. Declare free, strdup and strndup. (test11): New test. (main): Call it. * gcc.dg/builtin-object-size-2.c: Silence overread warnings. Declare free, strdup and strndup. (test9): New test. (main): Call it. * gcc.dg/builtin-object-size-3.c: Silence overread warnings. Declare free, strdup and strndup. (test11): New test. (main): Call it. * gcc.dg/builtin-object-size-4.c: Silence overread warnings. Declare free, strdup and strndup. (test9): New test. (main): Call it.
Diffstat (limited to 'libcpp')
0 files changed, 0 insertions, 0 deletions