Added a guaranteed null-terminate after call to strncpy.

This was partly found using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist <rickard_strandqv...@spectrumdigital.se>
---
 tools/perf/util/svghelper.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c
index 43262b8..cdcb332 100644
--- a/tools/perf/util/svghelper.c
+++ b/tools/perf/util/svghelper.c
@@ -255,9 +255,10 @@ static char *cpu_model(void)
        /* CPU type */
        file = fopen("/proc/cpuinfo", "r");
        if (file) {
-               while (fgets(buf, 255, file)) {
+               while (fgets(buf, sizeof(buf), 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;
                        }
                }
@@ -267,7 +268,7 @@ static char *cpu_model(void)
        /* CPU type */
        file = 
fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies", 
"r");
        if (file) {
-               while (fgets(buf, 255, file)) {
+               while (fgets(buf, sizeof(buf), file)) {
                        unsigned int freq;
                        freq = strtoull(buf, NULL, 10);
                        if (freq > max_freq)
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to