reallocarray: eliminate compilation warnings (#3798)
authorRong Tao <32674962+Rtoax@users.noreply.github.com>
Sat, 8 Jan 2022 19:36:00 +0000 (03:36 +0800)
committerGitHub <noreply@github.com>
Sat, 8 Jan 2022 19:36:00 +0000 (11:36 -0800)
there are compile warnings below for klockstat.

```bash
  CC       klockstat.o
klockstat.c: In function ‘print_stats’:
klockstat.c:396:12: warning: implicit declaration of function ‘reallocarray’; did you mean ‘realloc’? [-Wimplicit-function-declaration]
    stats = reallocarray(stats, stats_sz, sizeof(void *));
            ^~~~~~~~~~~~
            realloc
klockstat.c:396:10: warning: assignment to ‘struct stack_stat **’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
    stats = reallocarray(stats, stats_sz, sizeof(void *));
          ^
  BINARY   klockstat
```

Defining _GNU_SOURCE fixed the problem.

libbpf-tools/klockstat.c

index f16b760e2229ecd5589fcbe84e7eb21f6627b328..55b4fcf5db25942a7f8775e00900fbe95cd7ff4d 100644 (file)
@@ -14,6 +14,9 @@
 #include <errno.h>
 #include <signal.h>
 #include <stdio.h>
+#ifndef _GNU_SOURCE                                                                                                            
+#define _GNU_SOURCE
+#endif
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>