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 <>
    Message-ID:  <>

  | +            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,
	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.


Home | Main Index | Thread Index | Old Index