Re: [PATCH v2 4/5] parse-options: introduce `OPTION_UNSIGNED`

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

 



On 16/04/2025 11:27, Patrick Steinhardt wrote:
On Tue, Apr 15, 2025 at 04:52:02PM +0100, Phillip Wood wrote:

Wait, does it? Why would `strtoul()` or any of its variants ever accept
a string prefixed with a "-"?

     If the minus sign was part of the input sequence, the numeric value
     calculated from the sequence of digits is negated as if by unary
     minus in the result type, which applies unsigned integer wraparound
     rules.

Oh dear... all these integer conversion functions are really a gift that
keeps on giving. Gross.

Yes it's horrible behavior for a function that parses an unsigned integer. We should perhaps think about adding 64 bit versions of strtoui_i() and strtoul_ui() so we have a safer option for parsing large integers but I don't think we need to do that as part of this series.

I'll try and take a look at V3 tomorrow

Phillip

This patch also needs the fix from patch 2 to detect overflows for
uintmax_t.

Yup, will add.

Patrick





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux