diff options
Diffstat (limited to 'tools/perf/util/build-id.c')
| -rw-r--r-- | tools/perf/util/build-id.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index fdb35133fde4..3c286cdbe6e0 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -93,8 +93,11 @@ int build_id__snprintf(const struct build_id *build_id, char *bf, size_t bf_size return 0; } - for (size_t i = 0; i < build_id->size && offs < bf_size; ++i) - offs += snprintf(bf + offs, bf_size - offs, "%02x", build_id->data[i]); + if (bf_size > 0) + bf[0] = '\0'; + + for (size_t i = 0; i < build_id->size && offs + 1 < bf_size; ++i) + offs += scnprintf(bf + offs, bf_size - offs, "%02x", build_id->data[i]); return offs; } |
