From mboxrd@z Thu Jan 1 00:00:00 1970 From: Miquel Raynal Date: Mon, 3 Sep 2018 08:49:43 +0200 Subject: [U-Boot] [PATCH v7 02/13] lib: strto: fix metric suffix parsing in strtoul[l] In-Reply-To: <465b43da-6ff9-e5b9-7bbc-e958fe5e1ece@denx.de> References: <20180831145741.17350-1-miquel.raynal@bootlin.com> <20180831145741.17350-3-miquel.raynal@bootlin.com> <465b43da-6ff9-e5b9-7bbc-e958fe5e1ece@denx.de> Message-ID: <20180903084943.62e99526@xps13> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de Hi Stefan, Stefan Roese wrote on Sat, 1 Sep 2018 10:48:25 +0200: > On 31.08.2018 16:57, Miquel Raynal wrote: > > While 1kB or 1kiB will be parsed correctly, 1k will return the right > > amount, but the metric suffix will not be escaped once the char > > pointer updated. Fix this situation by simplifying the move of the > > endp pointer. =20 > > > Signed-off-by: Miquel Raynal =20 > > --- > > lib/strto.c | 22 ++++++++++------------ > > 1 file changed, 10 insertions(+), 12 deletions(-) =20 > > > diff --git a/lib/strto.c b/lib/strto.c =20 > > index 84f8d92d57..502a0153e7 100644 > > --- a/lib/strto.c > > +++ b/lib/strto.c > > @@ -97,12 +97,11 @@ unsigned long ustrtoul(const char *cp, char **endp,= unsigned int base) > > case 'K': > > case 'k': > > result *=3D 1024; > > - if ((*endp)[1] =3D=3D 'i') { > > - if ((*endp)[2] =3D=3D 'B') > > - (*endp) +=3D 3; > > - else > > - (*endp) +=3D 2; > > - } > > + (*endp)++; > > + if (**endp =3D=3D 'i') > > + (*endp)++; > > + if (**endp =3D=3D 'B') > > + (*endp)++; > > } > > return result; > > } > > @@ -122,12 +121,11 @@ unsigned long long ustrtoull(const char *cp, char= **endp, unsigned int base) > > case 'K': > > case 'k': > > result *=3D 1024; > > - if ((*endp)[1] =3D=3D 'i') { > > - if ((*endp)[2] =3D=3D 'B') > > - (*endp) +=3D 3; > > - else > > - (*endp) +=3D 2; > > - } > > + (*endp)++; > > + if (**endp =3D=3D 'i') > > + (*endp)++; > > + if (**endp =3D=3D 'B') > > + (*endp)++; > > } > > return result; > > } > > =20 > Even though KiB is not equal to KB in general (at least in Linux > userspace AFAIK), lets not change this in U-Boot and always use > KiB and KB as a representation for 1024 (instead of 1000). So: That's right I did not mentioned it in the commit log. I could update it to reflect that it is intentional to mix 'k' and 'kiB' as a representation of '* 12014' (already the case, but being clarified in the above change). Thanks, Miqu=C3=A8l