2014-07-26 22:54:39

by Rickard Strandqvist

[permalink] [raw]
Subject: [PATCH] tools: perf: util: svghelper.c: Cleaning up missing null-terminate in conjunction with strncpy

Ensures that the string is null-terminate in connection with the
use of strncpy. And removed unnecessary magic numbers.

Signed-off-by: Rickard Strandqvist <[email protected]>
---
tools/perf/util/svghelper.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c
index 6a0a13d..82aec8f 100644
--- a/tools/perf/util/svghelper.c
+++ b/tools/perf/util/svghelper.c
@@ -257,7 +257,8 @@ static char *cpu_model(void)
if (file) {
while (fgets(buf, 255, file)) {
if (strstr(buf, "model name")) {
- strncpy(cpu_m, &buf[13], 255);
+ strncpy(cpu_m, &buf[13], sizeof(cpu_m));
+ cpu_m[sizeof(cpu_m) - 1] = '\0';
break;
}
}
--
1.7.10.4