* [PATCH] tools/thermal/tmon: Fix string truncation warning in optarg copy
@ 2026-09-29 20:19 Florian Fainelli
0 siblings, 0 replies; only message in thread
From: Florian Fainelli @ 2026-09-29 20:19 UTC (permalink / raw)
To: linux-kernel
Cc: bcm-kernel-feedback-list, Florian Fainelli, Rafael J. Wysocki,
Daniel Lezcano, Zhang Rui, Lukasz Luba, Jacob Pan,
open list:THERMAL
GCC warns about possible string truncation with -Wstringop-truncation:
tmon.c: In function ‘main’:
tmon.c:233:25: warning: ‘__builtin_strncpy’ specified bound 20 equals
destination size [-Wstringop-truncation]
233 | strncpy(ctrl_cdev, optarg,
CDEV_NAME_SIZE);
|
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Replace strncpy() with snprintf() to guarantee NUL-termination and
silence the compiler warning.
Fixes: 94f69966faf8 ("tools/thermal: Introduce tmon, a tool for thermal subsystem")
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
tools/thermal/tmon/tmon.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/thermal/tmon/tmon.c b/tools/thermal/tmon/tmon.c
index 7eb3216a27f4..0c8deee4652e 100644
--- a/tools/thermal/tmon/tmon.c
+++ b/tools/thermal/tmon/tmon.c
@@ -230,7 +230,7 @@ int main(int argc, char **argv)
switch (c) {
case 'c':
no_control = 0;
- strncpy(ctrl_cdev, optarg, CDEV_NAME_SIZE);
+ snprintf(ctrl_cdev, sizeof(ctrl_cdev), "%s", optarg);
break;
case 'd':
start_daemon_mode();
--
2.34.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-09-29 20:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-29 20:19 [PATCH] tools/thermal/tmon: Fix string truncation warning in optarg copy Florian Fainelli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®