OSDN Git Service

Bugfix from Hyejin Kim (count=1 shouldn't change name), plus a bounds check.
authorRob Landley <rob@landley.net>
Tue, 21 Apr 2015 06:45:07 +0000 (01:45 -0500)
committerRob Landley <rob@landley.net>
Tue, 21 Apr 2015 06:45:07 +0000 (01:45 -0500)
Test is 'echo "AAA c 1 0 0 2 5 0 0 1" | makedevs' makes AAA not AAA0.

toys/other/makedevs.c

index 0d20a57..0f0a661 100644 (file)
@@ -84,8 +84,8 @@ void makedevs_main()
     while (*node == '/') node++; // using relative path
 
     for (i = 0; (!cnt && !i) || i < cnt; i++) {
-      if (cnt) {
-        snprintf(toybuf, sizeof(toybuf), "%s%u", node, st_val + i);
+      if (cnt>1) {
+        snprintf(toybuf, sizeof(toybuf), "%.999s%u", node, st_val + i);
         ptr = toybuf;
       } else ptr = node;