All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib: Improve _parse_integer_fixup_radix base 16 detection
@ 2020-02-07 12:07 Michal Simek
  2020-02-13  7:33 ` Michal Simek
  0 siblings, 1 reply; 4+ messages in thread
From: Michal Simek @ 2020-02-07 12:07 UTC (permalink / raw)
  To: u-boot

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The patch is checking all chars to make sure that they are not 'a' or
up. If they are base needs to be in hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

 lib/strto.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/lib/strto.c b/lib/strto.c
index 55ff9f7437d5..14821c87f16d 100644
--- a/lib/strto.c
+++ b/lib/strto.c
@@ -22,9 +22,25 @@ static const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
 				*base = 16;
 			else
 				*base = 8;
-		} else
+		} else {
+			int i;
+
 			*base = 10;
+
+			for (i = 0; ; i++) {
+				char var = s[i];
+
+				if (var == '\n')
+					break;
+
+				if (var >= 'a') {
+					*base = 16;
+					break;
+				}
+			}
+		}
 	}
+
 	if (*base == 16 && s[0] == '0' && tolower(s[1]) == 'x')
 		s += 2;
 	return s;
-- 
2.25.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] lib: Improve _parse_integer_fixup_radix base 16 detection
  2020-02-07 12:07 [PATCH] lib: Improve _parse_integer_fixup_radix base 16 detection Michal Simek
@ 2020-02-13  7:33 ` Michal Simek
  2020-02-13 12:30   ` Tom Rini
  0 siblings, 1 reply; 4+ messages in thread
From: Michal Simek @ 2020-02-13  7:33 UTC (permalink / raw)
  To: u-boot

p? 7. 2. 2020 v 13:07 odes?latel Michal Simek <michal.simek@xilinx.com> napsal:
>
> Base autodetection is failing for this case:
> if test 257 -gt 3ae; then echo first; else echo second; fi
>
> It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
> 10. The patch is checking all chars to make sure that they are not 'a' or
> up. If they are base needs to be in hex.
>
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> ---
>
>  lib/strto.c | 18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/lib/strto.c b/lib/strto.c
> index 55ff9f7437d5..14821c87f16d 100644
> --- a/lib/strto.c
> +++ b/lib/strto.c
> @@ -22,9 +22,25 @@ static const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
>                                 *base = 16;
>                         else
>                                 *base = 8;
> -               } else
> +               } else {
> +                       int i;
> +
>                         *base = 10;
> +
> +                       for (i = 0; ; i++) {
> +                               char var = s[i];
> +
> +                               if (var == '\n')
> +                                       break;
> +
> +                               if (var >= 'a') {
> +                                       *base = 16;
> +                                       break;
> +                               }
> +                       }
> +               }
>         }
> +
>         if (*base == 16 && s[0] == '0' && tolower(s[1]) == 'x')
>                 s += 2;
>         return s;
> --
> 2.25.0
>

Tom: Any comment on this one?

M


-- 
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] lib: Improve _parse_integer_fixup_radix base 16 detection
  2020-02-13  7:33 ` Michal Simek
@ 2020-02-13 12:30   ` Tom Rini
  2020-02-20  6:46     ` Michal Simek
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Rini @ 2020-02-13 12:30 UTC (permalink / raw)
  To: u-boot

On Thu, Feb 13, 2020 at 08:33:09AM +0100, Michal Simek wrote:
> p? 7. 2. 2020 v 13:07 odes?latel Michal Simek <michal.simek@xilinx.com> napsal:
> >
> > Base autodetection is failing for this case:
> > if test 257 -gt 3ae; then echo first; else echo second; fi
> >
> > It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
> > 10. The patch is checking all chars to make sure that they are not 'a' or
> > up. If they are base needs to be in hex.
> >
> > Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> > ---
> >
> >  lib/strto.c | 18 +++++++++++++++++-
> >  1 file changed, 17 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/strto.c b/lib/strto.c
> > index 55ff9f7437d5..14821c87f16d 100644
> > --- a/lib/strto.c
> > +++ b/lib/strto.c
> > @@ -22,9 +22,25 @@ static const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
> >                                 *base = 16;
> >                         else
> >                                 *base = 8;
> > -               } else
> > +               } else {
> > +                       int i;
> > +
> >                         *base = 10;
> > +
> > +                       for (i = 0; ; i++) {
> > +                               char var = s[i];
> > +
> > +                               if (var == '\n')
> > +                                       break;
> > +
> > +                               if (var >= 'a') {
> > +                                       *base = 16;
> > +                                       break;
> > +                               }
> > +                       }
> > +               }
> >         }
> > +
> >         if (*base == 16 && s[0] == '0' && tolower(s[1]) == 'x')
> >                 s += 2;
> >         return s;
> > --
> > 2.25.0
> >
> 
> Tom: Any comment on this one?

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200213/4ad79d52/attachment.sig>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] lib: Improve _parse_integer_fixup_radix base 16 detection
  2020-02-13 12:30   ` Tom Rini
@ 2020-02-20  6:46     ` Michal Simek
  0 siblings, 0 replies; 4+ messages in thread
From: Michal Simek @ 2020-02-20  6:46 UTC (permalink / raw)
  To: u-boot

?t 13. 2. 2020 v 13:30 odes?latel Tom Rini <trini@konsulko.com> napsal:
>
> On Thu, Feb 13, 2020 at 08:33:09AM +0100, Michal Simek wrote:
> > p? 7. 2. 2020 v 13:07 odes?latel Michal Simek <michal.simek@xilinx.com> napsal:
> > >
> > > Base autodetection is failing for this case:
> > > if test 257 -gt 3ae; then echo first; else echo second; fi
> > >
> > > It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
> > > 10. The patch is checking all chars to make sure that they are not 'a' or
> > > up. If they are base needs to be in hex.
> > >
> > > Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> > > ---
> > >
> > >  lib/strto.c | 18 +++++++++++++++++-
> > >  1 file changed, 17 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/lib/strto.c b/lib/strto.c
> > > index 55ff9f7437d5..14821c87f16d 100644
> > > --- a/lib/strto.c
> > > +++ b/lib/strto.c
> > > @@ -22,9 +22,25 @@ static const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
> > >                                 *base = 16;
> > >                         else
> > >                                 *base = 8;
> > > -               } else
> > > +               } else {
> > > +                       int i;
> > > +
> > >                         *base = 10;
> > > +
> > > +                       for (i = 0; ; i++) {
> > > +                               char var = s[i];
> > > +
> > > +                               if (var == '\n')

here should be \0

> > > +                                       break;
> > > +
> > > +                               if (var >= 'a') {

Colleague also suggested to check also till f here.

Will create v2 on this.

M



-- 
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-02-20  6:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-07 12:07 [PATCH] lib: Improve _parse_integer_fixup_radix base 16 detection Michal Simek
2020-02-13  7:33 ` Michal Simek
2020-02-13 12:30   ` Tom Rini
2020-02-20  6:46     ` Michal Simek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.