Discussion:
[Linuxwacom-devel] [PATCH libwacom] Fix compiler warning about possibly truncated file name
Peter Hutterer
2017-05-10 03:34:33 UTC
Permalink
list-local-devices.c:98:35: warning: ‘%s’ directive output may be truncated
writing up to 255 bytes into a region of size 52 [-Wformat-truncation=]
snprintf(fname, 63, "/dev/input/%s", namelist[i]->d_name);

Can't happen here, but rather than disable a potentially useful warning just
up the path to the max size.

Signed-off-by: Peter Hutterer <***@who-t.net>
---
tools/list-local-devices.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/list-local-devices.c b/tools/list-local-devices.c
index 6aa7600..2afb1a3 100644
--- a/tools/list-local-devices.c
+++ b/tools/list-local-devices.c
@@ -93,9 +93,9 @@ int main(int argc, char **argv)
}

while (i--) {
- char fname[64];
+ char fname[PATH_MAX];

- snprintf(fname, 63, "/dev/input/%s", namelist[i]->d_name);
+ snprintf(fname, sizeof(fname), "/dev/input/%s", namelist[i]->d_name);
dev = libwacom_new_from_path(db, fname, WFALLBACK_NONE, NULL);
if (!dev)
continue;
--
2.12.2
Jason Gerecke
2017-05-10 17:00:11 UTC
Permalink
Post by Peter Hutterer
list-local-devices.c:98:35: warning: ‘%s’ directive output may be truncated
writing up to 255 bytes into a region of size 52 [-Wformat-truncation=]
snprintf(fname, 63, "/dev/input/%s", namelist[i]->d_name);
Can't happen here, but rather than disable a potentially useful warning just
up the path to the max size.
---
tools/list-local-devices.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/list-local-devices.c b/tools/list-local-devices.c
index 6aa7600..2afb1a3 100644
--- a/tools/list-local-devices.c
+++ b/tools/list-local-devices.c
@@ -93,9 +93,9 @@ int main(int argc, char **argv)
}
while (i--) {
- char fname[64];
+ char fname[PATH_MAX];
- snprintf(fname, 63, "/dev/input/%s", namelist[i]->d_name);
+ snprintf(fname, sizeof(fname), "/dev/input/%s", namelist[i]->d_name);
dev = libwacom_new_from_path(db, fname, WFALLBACK_NONE, NULL);
if (!dev)
continue;
Looks good to me :)

79d049a..63631a0 master -> master
--
Jason
---
Now instead of four in the eights place /
you’ve got three, ‘Cause you added one /
(That is to say, eight) to the two, /
But you can’t take seven from three, /
So you look at the sixty-fours....
Loading...