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



On 24.11.2019 08:56, Alexander Kuleshov wrote:
> I sorry for noise, but wrong artifact hit to the first one patch,
> here is the update:
> 

strtoi(3) is easier here than strtol(3).

> 
> 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++;
> 


Attachment: signature.asc
Description: OpenPGP digital signature



Home | Main Index | Thread Index | Old Index