Re: [U-Boot] [PATCH v7 01/13] lib: strto: parse all lowercase metric prefixes in ustrtoul[l]
Hi Stefan, Stefan Roese wrote on Sat, 1 Sep 2018 10:43:01 +0200: > On 31.08.2018 16:57, Miquel Raynal wrote: > > Both ustrtoul and ustrtoull interpret 1k but not 1m or 1g. Even if the > > SI symbols for Mega and Giga are 'M' and 'G', certain entries of > > eg. mtdparts also use (wrongly) the metric prefix 'm' and 'g'. > > > I do not see how parsing lowercase prefixes could break anything, so > > parse them like their uppercase counterpart. > > > Signed-off-by: Miquel Raynal > > --- > > lib/strto.c | 4 > > 1 file changed, 4 insertions(+) > > > diff --git a/lib/strto.c b/lib/strto.c > > index 7f6076909a..84f8d92d57 100644 > > --- a/lib/strto.c > > +++ b/lib/strto.c > > @@ -87,9 +87,11 @@ unsigned long ustrtoul(const char *cp, char **endp, > > unsigned int base) > > unsigned long result = simple_strtoul(cp, endp, base); > > switch (**endp) { > > case 'G': > > + case 'g': > > result *= 1024; > > /* fall through */ > > case 'M': > > + case 'm': > > result *= 1024; > > /* fall through */ > > case 'K': > > @@ -110,9 +112,11 @@ unsigned long long ustrtoull(const char *cp, char > > **endp, unsigned int base) > > unsigned long long result = simple_strtoull(cp, endp, base); > > switch (**endp) { > > case 'G': > > + case 'g': > > result *= 1024; > > /* fall through */ > > case 'M': > > + case 'm': > > Wouldn't it be better, to use tolower() on the char and drop all the > upper case checks completely - also for the 'K' case? Sure, I can do that! Thanks, Miquèl ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [PATCH v7 01/13] lib: strto: parse all lowercase metric prefixes in ustrtoul[l]
On 31.08.2018 16:57, Miquel Raynal wrote: Both ustrtoul and ustrtoull interpret 1k but not 1m or 1g. Even if the SI symbols for Mega and Giga are 'M' and 'G', certain entries of eg. mtdparts also use (wrongly) the metric prefix 'm' and 'g'. I do not see how parsing lowercase prefixes could break anything, so parse them like their uppercase counterpart. Signed-off-by: Miquel Raynal --- lib/strto.c | 4 1 file changed, 4 insertions(+) diff --git a/lib/strto.c b/lib/strto.c index 7f6076909a..84f8d92d57 100644 --- a/lib/strto.c +++ b/lib/strto.c @@ -87,9 +87,11 @@ unsigned long ustrtoul(const char *cp, char **endp, unsigned int base) unsigned long result = simple_strtoul(cp, endp, base); switch (**endp) { case 'G': + case 'g': result *= 1024; /* fall through */ case 'M': + case 'm': result *= 1024; /* fall through */ case 'K': @@ -110,9 +112,11 @@ unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base) unsigned long long result = simple_strtoull(cp, endp, base); switch (**endp) { case 'G': + case 'g': result *= 1024; /* fall through */ case 'M': + case 'm': Wouldn't it be better, to use tolower() on the char and drop all the upper case checks completely - also for the 'K' case? Thanks, Stefan ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
[U-Boot] [PATCH v7 01/13] lib: strto: parse all lowercase metric prefixes in ustrtoul[l]
Both ustrtoul and ustrtoull interpret 1k but not 1m or 1g. Even if the SI symbols for Mega and Giga are 'M' and 'G', certain entries of eg. mtdparts also use (wrongly) the metric prefix 'm' and 'g'. I do not see how parsing lowercase prefixes could break anything, so parse them like their uppercase counterpart. Signed-off-by: Miquel Raynal --- lib/strto.c | 4 1 file changed, 4 insertions(+) diff --git a/lib/strto.c b/lib/strto.c index 7f6076909a..84f8d92d57 100644 --- a/lib/strto.c +++ b/lib/strto.c @@ -87,9 +87,11 @@ unsigned long ustrtoul(const char *cp, char **endp, unsigned int base) unsigned long result = simple_strtoul(cp, endp, base); switch (**endp) { case 'G': + case 'g': result *= 1024; /* fall through */ case 'M': + case 'm': result *= 1024; /* fall through */ case 'K': @@ -110,9 +112,11 @@ unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base) unsigned long long result = simple_strtoull(cp, endp, base); switch (**endp) { case 'G': + case 'g': result *= 1024; /* fall through */ case 'M': + case 'm': result *= 1024; /* fall through */ case 'K': -- 2.17.1 ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot