bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: side effects of split() parameter


From: Aharon Robbins
Subject: Re: side effects of split() parameter
Date: Tue, 14 May 2002 18:52:14 +0300

Applied. Thanks.  --Arnold

> Date: Mon, 13 May 2002 16:17:58 +0200
> From: Stepan Kasal <address@hidden>
> To: address@hidden
> Subject: side effects of split() parameter
>
> Hallo Aharon,
>       I've found the following bug:
>
> $ awk 'BEGIN{s="";a[1]=7;split("",b,split("",a));print a[1]}'
> 7
>
> Patch is attached.
>
> The bug also appears in sub/gsub/gensub, but the patch doesn't cover this
> since I'm trying to rewrite sub_common in a more transparent way and I'm
> going to offer you the result in a few days.
>
> Do you know about other builtins which may also discard a parameter without
> evaluating it?
>
> I have an idea that during compile time, the nodes are marked by a SIDEEFF
> bit (SIDEEFF==0 implies there are surely no side effects).
> The bit is defined by an intuitive recursive definition.
> This would for example avoid evaluation of the parameter if it's just an
> expensive concatenation.
> But I won't have time for this any time soon, I'm afraid.
>
> Stepan Kasal
>
> --C7zPtVaVf+AK4Oqc
> Content-Type: text/plain; charset=us-ascii
> Content-Disposition: attachment; filename="gawk-3.1.1-split_sideeff.patch"
>
> This patch fixes the following bug:
>
> $ awk 'BEGIN{s="";a[1]=7;split("",b,split("",a));print a[1]}'
> 7
>
> --- gawk-3.1.1/field.c.orig   Mon May 13 14:56:04 2002
> +++ gawk-3.1.1/field.c        Mon May 13 14:55:17 2002
> @@ -855,6 +855,16 @@ do_split(NODE *tree)
>                * Skip the work if first arg is the null string.
>                * Check after clearing the array, to preserve
>                * correct semantics.
> +              *
> +              * But if sep is not FS, evaluate it, since it may have
> +              * sideeffects.
> +              */
> +             if ((sep->re_flags & FS_DFLT) == 0)
> +                     free_temp(tree_eval(sep->re_exp));
> +             /*
> +              * FIXME: the above call should be also avoided in other
> +              * cases when it's clear that sep has no side effects.
> +              * (That would require an analysis during the compile time.)
>                */
>               tmp = tmp_number((AWKNUM) 0);
>               goto out;
>
> --C7zPtVaVf+AK4Oqc--



reply via email to

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