aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Hunter <[email protected]>2023-03-16 21:41:56 +0200
committerArnaldo Carvalho de Melo <[email protected]>2023-04-04 09:39:56 -0300
commitf5ceb159d30b87975a49b8a230ffa76bae6684b2 (patch)
tree799e9a43e84d5a9e583bd4ad68103c07ae2903ac
parenta2410b579c72242ac0f77b3768093d8c1b48012e (diff)
perf tools: Avoid warning in do_realloc_array_as_needed()
do_realloc_array_as_needed() used memcpy() of zero size with a NULL pointer. Check the size first to avoid sanitize warning. Discovered using EXTRA_CFLAGS="-fsanitize=undefined -fsanitize=address". Reported-by: kernel test robot <[email protected]> Signed-off-by: Adrian Hunter <[email protected]> Acked-by: Ian Rogers <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Link: https://lore.kernel.org/oe-lkp/[email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
-rw-r--r--tools/perf/util/util.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index b356c9f7f0c3..089208b51e68 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -524,7 +524,8 @@ int do_realloc_array_as_needed(void **arr, size_t *arr_sz, size_t x, size_t msz,
new_arr = calloc(new_sz, msz);
if (!new_arr)
return -ENOMEM;
- memcpy(new_arr, *arr, *arr_sz * msz);
+ if (*arr_sz)
+ memcpy(new_arr, *arr, *arr_sz * msz);
if (init_val) {
for (i = *arr_sz; i < new_sz; i++)
memcpy(new_arr + (i * msz), init_val, msz);