lib: Improve _parse_integer_fixup_radix base 16 detection
PATCH 1/1 lib: Improve _parse_integer_fixup_radix base 16 detection
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.
---
lib/strto.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
lib/strto.c +17 -1
@@ -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;
Signature · 1 line
2.25.0
PATCH 1/1 lib: Improve _parse_integer_fixup_radix base 16 detection
p? 7. 2. 2020 v 13:07 odes?latel Michal Simek <[email protected]> napsal:
Quoted 46 lines
Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fiIt 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 <[email protected]>---
lib/strto.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)lib/strto.c +17
-2@@ -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; --
Quoted 2 lines
2.25.0
Tom: Any comment on this one?
M
Signature · 5 lines
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
PATCH 1/1 lib: Improve _parse_integer_fixup_radix base 16 detection
Quoted 43 lines · Michal Simek
p? 7. 2. 2020 v 13:07 odes?latel Michal Simek <[email protected]> napsal:
Quoted 42 lines
Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fiIt 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 <[email protected]>---
lib/strto.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)lib/strto.c +17
-1@@ -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 ; + } + } + } } +
Quoted 8 lines
Quoted 6 lines
lib/strto.c +0
-1if (*base ==16 && s[0 ] =='0' &&tolower (s[1 ]) =='x' ) s +=2 ;return s; --2.25.0
Tom: Any comment on this one?
Signature · 8 lines
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>
PATCH 1/1 lib: Improve _parse_integer_fixup_radix base 16 detection
?t 13. 2. 2020 v 13:30 odes?latel Tom Rini <[email protected]> napsal:
Quoted 27 lines · Michal Simek
Quoted 25 lines
p? 7. 2. 2020 v 13:07 odes?latel Michal Simek <[email protected]> napsal:
Quoted 24 lines
Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fiIt 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 <[email protected]>---
lib/strto.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)lib/strto.c +1
-1@@ -22,9 +22,25 @@ static const char *_parse_integer_fixup_radix(const char *s, unsigned int *base) *base =16 ; else *base =8 ; - }else + }else {
Quoted 8 lines
Quoted 8 lines
lib/strto.c static const char *_parse_integer_fixup_radix(const char *s, unsigned int *base) · line 33
Quoted 8 lines
lib/strto.c +7
-0+int i; + *base =10 ; + +for (i =0 ; ; i++) { +char var = s[i]; + +if (var =='\n' )
here should be \0
Quoted 3 lines
Quoted 3 lines
lib/strto.c static const char *_parse_integer_fixup_radix(const char *s, unsigned int *base) · line 36
Quoted 3 lines
lib/strto.c +3
-0+break ; + +if (var >='a' ) {
Colleague also suggested to check also till f here.
Will create v2 on this.
M
Signature · 5 lines
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