bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Skip initial expansion of valid array reference tokens in un


From: Koichi Murase
Subject: Re: [PATCH] Skip initial expansion of valid array reference tokens in unset
Date: Tue, 20 Apr 2021 03:08:08 +0900

2021年4月20日(火) 0:16 konsolebox <konsolebox@gmail.com>:
> Attached patch demonstrates a solution that solves the current issues
> of unset discussed in
> https://lists.gnu.org/archive/html/bug-bash/2021-03/msg00056.html
> while avoiding breakage of scripts and keeping the expansion of
> subscripts consistent with expansion in references.

Nice demonstration!  I haven't tried but have comments after taking a
glance at the patch.

> diff --git a/command.h b/command.h
> index 914198f..4dafcf0 100644
> --- a/command.h
> +++ b/command.h
> @@ -104,6 +104,7 @@ enum command_type { cm_for, cm_case, cm_while, cm_if, 
> cm_simple, cm_select,
>  #define W_CHKLOCAL (1 << 28) /* check for local vars on assignment */
>  #define W_NOASSNTILDE (1 << 29) /* don't do tilde expansion like an 
> assignment statement */
>  #define W_FORCELOCAL (1 << 30) /* force assignments to be to local 
> variables, non-fatal on assignment errors */
> +#define W_NOEXPAND (1 << 31) /* inhibits any form of expansion */

AFAIK `1 << 31' causes undefined behavior when int is 32-bit signed
integer.  Instead, I think you may write `(int)(1u << 31)' for
conforming C compilers. `u << 31' is defined for unsigned integers,
and the conversion between signed and unsigned integers is defined to
be made by mod 2^{32} (when int is 32 bits).

> diff --git a/y.tab.c b/y.tab.c
> index dcc5b7f..a9ae0e6 100644
> --- a/y.tab.c
> +++ b/y.tab.c
> @@ -7700,7 +7700,15 @@ got_token:

`y.tab.c' is automatically generated from `parse.y'. You should edit
`parse.y' instead of `y.tab.c'.  The corresponding lines are
parse.y:5512--5517.  To regenerate `y.tab.c' after the edit, maybe you
need bison (or yacc).

--
Koichi



reply via email to

[Prev in Thread] Current Thread [Next in Thread]