Skip to content

Commit 91de381

Browse files
chenhengqiyonghong-song
authored andcommitted
libbpf-tools: Fix compilation error for gethostlatency
Fix the following compilation error with GCC 8.5.0: gethostlatency.c: In function ‘attach_uprobes.isra.2’: gethostlatency.c:157:58: error: ‘%s’ directive output may be truncated writing up to 4095 bytes into a region of size between 4074 and 4084 [-Werror=format-truncation=] snprintf(proc_path, sizeof(proc_path), "/proc/%d/root%s", target_pid, buf); ^~ ~~~ gethostlatency.c:157:5: note: ‘snprintf’ output between 13 and 4118 bytes into a destination of size 4096 snprintf(proc_path, sizeof(proc_path), "/proc/%d/root%s", target_pid, buf); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
1 parent 8446572 commit 91de381

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

libbpf-tools/gethostlatency.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,11 @@ static void handle_lost_events(void *ctx, int cpu, __u64 lost_cnt)
124124

125125
static int get_libc_path(char *path)
126126
{
127-
FILE *f;
127+
char proc_path[PATH_MAX + 32] = {};
128128
char buf[PATH_MAX] = {};
129-
char map_fname[PATH_MAX] = {};
130-
char proc_path[PATH_MAX] = {};
131129
char *filename;
132130
float version;
131+
FILE *f;
133132

134133
if (libc_path) {
135134
memcpy(path, libc_path, strlen(libc_path));
@@ -139,8 +138,8 @@ static int get_libc_path(char *path)
139138
if (target_pid == 0) {
140139
f = fopen("/proc/self/maps", "r");
141140
} else {
142-
snprintf(map_fname, sizeof(map_fname), "/proc/%d/maps", target_pid);
143-
f = fopen(map_fname, "r");
141+
snprintf(buf, sizeof(buf), "/proc/%d/maps", target_pid);
142+
f = fopen(buf, "r");
144143
}
145144
if (!f)
146145
return -errno;

0 commit comments

Comments
 (0)