tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: [patch] usbdevs(8) use strtol(3) instead of atoi(3) for more predictable result



I sorry for noise, but wrong artifact hit to the first one patch,
here is the update:


diff --git a/usr.sbin/usbdevs/usbdevs.c b/usr.sbin/usbdevs/usbdevs.c
index e8fe1e7e6f4..526c1eade38 100644
--- a/usr.sbin/usbdevs/usbdevs.c
+++ b/usr.sbin/usbdevs/usbdevs.c
@@ -372,11 +372,14 @@ main(int argc, char **argv)
     char *dev = NULL;
     int addr = -1;
     int ncont;
+    char *ep;

     while ((ch = getopt(argc, argv, "a:df:v?")) != -1) {
         switch(ch) {
         case 'a':
-            addr = atoi(optarg);
+            addr = strtol(optarg, &ep, 10);
+            if (*ep != '\0' || addr < 0)
+                errx(EINVAL, "bad value for device address - %s", optarg);
             break;
         case 'd':
             showdevs++;


Home | Main Index | Thread Index | Old Index