dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [BUG] ${#10}
@ 2021-02-05  8:49 Vladimir N. Oleynik
  2021-02-08  3:41 ` [PATCH] parser: Fix regression on ${#10} expansion Herbert Xu
  0 siblings, 1 reply; 4+ messages in thread
From: Vladimir N. Oleynik @ 2021-02-05  8:49 UTC (permalink / raw)
  To: dash

[-- Attachment #1: Type: text/plain, Size: 280 bytes --]

Hello.

dash have bug for ${#10} and etc: ignores 0... in name (without errors :)

$ foo() { echo "length 10-th arg '${10}' is ${#10}"; }
$ foo a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11
length 10-th arg 'a10' is 2

But need:
length 10-th arg 'a10' is 3


Micro patch attached


--w
vodz

[-- Attachment #2: lenght-na_bug.diff.txt --]
[-- Type: text/plain, Size: 323 bytes --]

--- parser.c~	2021-02-04 00:51:34.000000000 +0400
+++ parser.c	2021-02-05 12:42:43.616635640 +0400
@@ -1274,7 +1274,7 @@
 			do {
 				STPUTC(c, out);
 				c = pgetc_eatbnl();
-			} while (!subtype && is_digit(c));
+			} while ((!subtype || subtype == VSLENGTH) && is_digit(c));
 		} else if (c != '}') {
 			int cc = c;
 

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

* [PATCH] parser: Fix regression on ${#10} expansion
  2021-02-05  8:49 [PATCH] [BUG] ${#10} Vladimir N. Oleynik
@ 2021-02-08  3:41 ` Herbert Xu
  2021-02-10 15:30   ` Vladimir N. Oleynik
  0 siblings, 1 reply; 4+ messages in thread
From: Herbert Xu @ 2021-02-08  3:41 UTC (permalink / raw)
  To: Vladimir N. Oleynik; +Cc: dash

Thanks for the patch!

---8<---
Vladimir N. Oleynik <dzo@simtreas.ru> wrote:
> 
> dash have bug for ${#10} and etc: ignores 0... in name (without errors :)
> 
> $ foo() { echo "length 10-th arg '${10}' is ${#10}"; }
> $ foo a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11
> length 10-th arg 'a10' is 2
> 
> But need:
> length 10-th arg 'a10' is 3
> 
> Micro patch attached
>
> --- parser.c~   2021-02-04 00:51:34.000000000 +0400
> +++ parser.c    2021-02-05 12:42:43.616635640 +0400
> @@ -1274,7 +1274,7 @@
>                        do {
>                                STPUTC(c, out);
>                                c = pgetc_eatbnl();
> -                       } while (!subtype && is_digit(c));
> +                       } while ((!subtype || subtype == VSLENGTH) && is_digit(c));
>                } else if (c != '}') {
>                        int cc = c;

I would rather test against VSNORMAL.

Fixes: 7710a926b321 ("parser: Only accept single-digit parameter...")
Reported-by: Vladimir N. Oleynik <dzo@simtreas.ru>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/src/parser.c b/src/parser.c
index 3c80d17..834d2e3 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1252,7 +1252,7 @@ varname:
 			do {
 				STPUTC(c, out);
 				c = pgetc_eatbnl();
-			} while (!subtype && is_digit(c));
+			} while (subtype != VSNORMAL && is_digit(c));
 		} else if (c != '}') {
 			int cc = c;
 
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [PATCH] parser: Fix regression on ${#10} expansion
  2021-02-08  3:41 ` [PATCH] parser: Fix regression on ${#10} expansion Herbert Xu
@ 2021-02-10 15:30   ` Vladimir N. Oleynik
  2021-02-11  4:55     ` Herbert Xu
  0 siblings, 1 reply; 4+ messages in thread
From: Vladimir N. Oleynik @ 2021-02-10 15:30 UTC (permalink / raw)
  To: Herbert Xu; +Cc: dash

Hello, Herbert.

Herbert Xu wrote:

> Thanks for the patch!

> I would rather test against VSNORMAL.

Yes, its true for support indirection ${!var}
and realized by me :)

But I do not show this patch in
https://git.kernel.org/pub/scm/utils/dash/dash.git/
Its ok?


--w
vodz


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

* Re: [PATCH] parser: Fix regression on ${#10} expansion
  2021-02-10 15:30   ` Vladimir N. Oleynik
@ 2021-02-11  4:55     ` Herbert Xu
  0 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2021-02-11  4:55 UTC (permalink / raw)
  To: Vladimir N. Oleynik; +Cc: dash

On Wed, Feb 10, 2021 at 07:30:17PM +0400, Vladimir N. Oleynik wrote:
>
> But I do not show this patch in
> https://git.kernel.org/pub/scm/utils/dash/dash.git/
> Its ok?

It's still in the review process:

https://patchwork.kernel.org/project/dash/list/

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

end of thread, other threads:[~2021-02-11  4:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-05  8:49 [PATCH] [BUG] ${#10} Vladimir N. Oleynik
2021-02-08  3:41 ` [PATCH] parser: Fix regression on ${#10} expansion Herbert Xu
2021-02-10 15:30   ` Vladimir N. Oleynik
2021-02-11  4:55     ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).