[Toybox] [Patch] Fix atolx "not integer" error when used with suffix b, c or d
Minghui Liu
minghui.liu.95 at gmail.com
Tue Mar 20 17:59:30 PDT 2018
> On Mar 20, 2018, at 5:48 PM, Minghui Liu <minghui.liu.95 at gmail.com> wrote:
>
>> On Mar 20, 2018, at 5:20 PM, Rob Landley <rob at landley.net> wrote:
>>
>> On 03/15/2018 08:04 PM, Minghui Liu wrote:
>>> From bf7875ae127d1d172cbf5cea48755c8773f46df8 Mon Sep 17 00:00:00 2001
>>> From: Minghui Liu <minghui.liu.95 at gmail.com>
>>> Date: Thu, 15 Mar 2018 17:50:59 -0700
>>> Subject: [PATCH] Fix atolx "not integer" error when used with suffix b,c or d
>>
>> Except d indicates the previous unit is decimal instead of binary. By itself it
>> doesn't mean anything.
>
> What I meant was all the *d suffixs like kd, md, gd, etc.
> atolx() still complains “not integer” when used with these suffixs.
>
>>
>>> val = xstrtol(numstr, &c, 0);
>>> - if (c != numstr && *c && (end = strchr(suffixes, tolower(*c)))) {
>>> + if (c != numstr && *c && (end = strchr(suffixes, tolower(*c++)))) {
>>> int shift = end-suffixes-2;
>>
>> This increments c even if it's not in suffixes, so it will consume (and discard)
>> an unknown value. (Ala "truncate -s 1z file", not reported as an error.)
>
> Yes you are right. My bad.
>
>>
>> The increment pretty much has to be its own line, it has to be inside the
>> if(strchr()) curly brackets, but has to apply to all three shift categories.
>
> The (shift > 0) case needs to check for a ‘d’ character. If there is a ‘d’ we need an extra increment.
I meant the (shift > 0) case needs to check if c==NULL before it checks if c is‘d'. Basically:
if (*c && toupper(*c++)==‘d’)
>
>>
>> Checked in a fix, thanks for the heads up.
>>
>> Rob
>
> I am sending another patch now.
>
> Regards,
> Minghui
>
More information about the Toybox
mailing list