Commit 97acec7d authored by Shawn Landden's avatar Shawn Landden Committed by Arnaldo Carvalho de Melo
Browse files

perf data: Fix 'strncat may truncate' build failure with recent gcc

This strncat() is safe because the buffer was allocated with zalloc(),
however gcc doesn't know that. Since the string always has 4 non-null
bytes, just use memcpy() here.

    CC       /home/shawn/linux/tools/perf/util/data-convert-bt.o
  In file included from /usr/include/string.h:494,
                   from /home/shawn/linux/tools/lib/traceevent/event-parse.h:27,
                   from util/data-convert-bt.c:22:
  In function ‘strncat’,
      inlined from ‘string_set_value’ at util/data-convert-bt.c:274:4:
  /usr/include/powerpc64le-linux-gnu/bits/string_fortified.h:136:10: error: ‘__builtin_strncat’ output may be truncated copying 4 bytes from a string of length 4 [-Werror=stringop-truncation]
    136 |   return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest));
        |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: default avatarShawn Landden <>
Cc: Adrian Hunter <>
Cc: Jiri Olsa <>
Cc: Namhyung Kim <>
Cc: Wang Nan <>

Signed-off-by: default avatarArnaldo Carvalho de Melo <>
parent 5bdd9ad8
......@@ -271,7 +271,7 @@ static int string_set_value(struct bt_ctf_field *field, const char *string)
if (i > 0)
strncpy(buffer, string, i);
strncat(buffer + p, numstr, 4);
memcpy(buffer + p, numstr, 4);
p += 3;
Supports Markdown
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