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

From: [email-masked]
Date: Wed, 16 Apr 2025 14:31:44 +0100

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