perf top: Remove needless malloc(0) call that triggers -Walloc-size 35/314735/1
authorSun Haiyong <sunhaiyong@loongson.cn>
Mon, 4 Dec 2023 08:20:55 +0000 (16:20 +0800)
committerJaehoon Chung <jh80.chung@samsung.com>
Thu, 18 Jul 2024 07:47:31 +0000 (16:47 +0900)
GCC 14 introduces a new -Walloc-size included in -Wextra which errors out
like:

  builtin-top.c: In function ‘prompt_integer’:
  builtin-top.c:360:21: error: allocation of insufficient size ‘0’ for
  type ‘char’ with size ‘1’ [-Werror=alloc-size]
    360 |         char *buf = malloc(0), *p;
        |                     ^~~~~~

Just set it to NULL, getline() will do the allocation.

Signed-off-by: Sun Haiyong <sunhaiyong@loongson.cn>
Signed-off-by: Yanteng Si <siyanteng@loongson.cn>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20231204082055.91877-1-siyanteng@loongson.cn
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
[cherry picked from commit 79baac8acfc60a7a5114f6d60731e28c242ef8ce]
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Change-Id: Ia34af97505a9d0d0fce380a1393488a8d8a2499a

tools/perf/builtin-top.c

index 4b3ff7687236e450550879a6f55d551da9507a09..d2a32c4f04aa8cb71df214f32f72fbcf050aa1ce 100644 (file)
@@ -355,7 +355,7 @@ static void perf_top__print_sym_table(struct perf_top *top)
 
 static void prompt_integer(int *target, const char *msg)
 {
-       char *buf = malloc(0), *p;
+       char *buf = NULL, *p;
        size_t dummy = 0;
        int tmp;