[Toybox] [Patch] Fix atolx "not integer" error when used with suffix b, c or d

Rob Landley rob at landley.net
Tue Mar 20 17:20:00 PDT 2018


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.

>    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.)

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.

Checked in a fix, thanks for the heads up.

Rob



More information about the Toybox mailing list