[PATCH][V2] cpu: maxfreq: fix build errors on arm32 + gcc10
Alex Hung
alex.hung at canonical.com
Fri Jan 8 16:11:16 UTC 2021
The below errors were observed on armhf with Groovy and Hirsute
cpu/maxfreq/maxfreq.c:28:23: error: ‘%s’ directive output may be
truncated writing between 3 and 2147483645 bytes into a region of
size 4072 [-Werror=format-truncation=]
28 | #define CPU_FREQ_PATH "/sys/devices/system/cpu"
| ^~~~~~~~~~~~~~~~~~~~~~~~~
cpu/maxfreq/maxfreq.c:143:4: note: in expansion of macro ‘CPU_FREQ_PATH’
143 | CPU_FREQ_PATH "/%s/cpufreq/scaling_available_frequencies",
| ^~~~~~~~~~~~~
cpu/maxfreq/maxfreq.c:143:20: note: format string is defined here
143 | CPU_FREQ_PATH "/%s/cpufreq/scaling_available_frequencies",
| ^~
Signed-off-by: Alex Hung <alex.hung at canonical.com>
---
src/cpu/maxfreq/maxfreq.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/cpu/maxfreq/maxfreq.c b/src/cpu/maxfreq/maxfreq.c
index 168a69e8..a177e957 100644
--- a/src/cpu/maxfreq/maxfreq.c
+++ b/src/cpu/maxfreq/maxfreq.c
@@ -24,6 +24,7 @@
#include <dirent.h>
#include <ctype.h>
#include <math.h>
+#include <bsd/string.h>
#define CPU_FREQ_PATH "/sys/devices/system/cpu"
#define CPU_INFO_PATH "/proc/cpuinfo"
@@ -139,9 +140,9 @@ static int maxfreq_test1(fwts_framework *fw)
strlen(entry->d_name) < 3)
continue;
- snprintf(path, sizeof(path),
- CPU_FREQ_PATH "/%s/cpufreq/scaling_available_frequencies",
- entry->d_name);
+ strlcpy(path, CPU_FREQ_PATH, strlen(CPU_FREQ_PATH) + 1);
+ snprintf(path + strlen(CPU_FREQ_PATH), sizeof(path) - strlen(CPU_FREQ_PATH),
+ "/%s/cpufreq/scaling_available_frequencies", entry->d_name);
if ((data = fwts_get(path)) == NULL)
continue;
@@ -214,4 +215,3 @@ static fwts_framework_ops maxfreq_ops = {
};
FWTS_REGISTER("maxfreq", &maxfreq_ops, FWTS_TEST_ANYTIME, FWTS_FLAG_BATCH)
-
--
2.25.1
More information about the fwts-devel
mailing list