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



    Date:        Sun, 24 Nov 2019 13:49:56 +0600
    From:        Alexander Kuleshov <kuleshovmail%gmail.com@localhost>
    Message-ID:  <CANCZXo6_3wpRHKz2cFq3V0NA4BWO3tgaJA5emGFm1-qib45Y6Q%mail.gmail.com@localhost>

  | +            addr = strtol(optarg, &ep, 10);

  | Any comments?

strtol() returns a long, addr is just int - something needs to be
adjusted to avoid value truncation, depending upon what's acceptable,
maybe
	laddr = strtol(optarg, &ep, 10);
and then after the error checks (or merged in with them)
	if (laddr > INT_MAX)		/* < 0 test already happened */
		err("out of range");
	addr = (int)laddr;
(the cast is most likely not really needed).

Alternatively, maybe addr could be made long rather than int.  Depends
on how it is used.

Apart from that, where it is possible, removing uses of atoi() is
generally a good thing.

kre



Home | Main Index | Thread Index | Old Index