Commit f5ceb159 authored by Adrian Hunter's avatar Adrian Hunter Committed by Arnaldo Carvalho de Melo

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: default avatarkernel test robot <yujie.liu@intel.com>
Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Acked-by: default avatarIan Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/oe-lkp/202303061424.6ad43294-yujie.liu@intel.com
Link: https://lore.kernel.org/r/20230316194156.8320-2-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent a2410b57
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment