tools/thermal/tmon: Fix string truncation warning in optarg copy
PATCH 1/1 tools/thermal/tmon: Fix string truncation warning in optarg copy
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.
--- tools/thermal/tmon/tmon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/thermal/tmon/tmon.c +1 -1
@@ -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 ();
Signature · 1 line
2.34.1
Daniel Lezcano
AppliedQuoted 8 lines · Florian Fainelli
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); |
Quoted 8 lines
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Replace
strncpy()withsnprintf()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 <[email protected]>---
Applied, thanks
The following commit has been merged into the thermal/linux-next branch of thermal:
The following commit has been merged into the thermal/linux-next branch of thermal:
Commit-ID: 602da762f7a7c494a95cb204ac005965b214e556 Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//602da762f7a7c494a95cb204ac005965b214e556 Author: Florian Fainelli <[email protected]> AuthorDate: Tue, 29 Sep 2026 13:19:51 -07:00 Committer: Daniel Lezcano <[email protected]> CommitterDate: Wed, 14 Oct 2026 09:45:40 +02:00
tools/thermal/tmon: Fix string truncation warning in optarg copy
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.
--- tools/thermal/tmon/tmon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/thermal/tmon/tmon.c +1 -1
@@ -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 ();