bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Error messages on negative arguments for `and(a, b)/or(a,


From: Koichi Murase
Subject: Re: [bug-gawk] Error messages on negative arguments for `and(a, b)/or(a, b)/xor(a, b)'
Date: Tue, 23 Jul 2019 07:19:45 +0900

Hi Andy,

Thank you for your patch! Yes, your patch fixed it.

I looked into the source code. I think the local variable `i' in
`do_xor' can also be eliminated similarly to `do_and' and `do_or'
because `0 ^ uval == uval' (see an attached patch 0002-....patch).

Also the initial value `res = ~0;' in `do_and' is subtle although the
result would be fine in most environments; `0' is signed integer, so
`~0' becomes `-1' of type `int' (usually 32 bit) in environments with
two's complement representation. Then, when `-1' (32 bit) is converted
to `uintmax_t' (usually 64 bit) using "mod 2^64", it will become
`UINTMAX_MAX' with all their bits "one". Here I guess the original
intent was `res = ~(uintmax_t) 0;' (see another patch 0003-....patch).
But maybe I miss something. What do you think of this?

Regards,
Koichi

2019年7月23日(火) 4:46 Andrew J. Schorr <address@hidden>:
>
> Hi,
>
> On Mon, Jul 22, 2019 at 08:30:29PM +0900, Koichi Murase wrote:
> > I think "argument 1" and "argument 2" appearing in the error messages
> > on negative arguments for `and(a, b)', `or(a, b)' and `xor(a, b)' are
> > reversed. I'm using gawk-5.0, but It is also reproduced for the latest
> > commit 680bf3fd.
> >
> > $ gawk-devel --version
> > GNU Awk 5.0.60, API: 3.0
> > Copyright (C) 1989, 1991-2019 Free Software Foundation.
> > ---(snip)---
> > $ LC_ALL=C gawk-devel 'BEGIN{print or(-1,1);exit}'
> > gawk-devel: cmd. line:1: fatal: or: argument 2 negative value -1 is not 
> > allowed
> > $ LC_ALL=C gawk-devel 'BEGIN{print or(1,-1);exit}'
> > gawk-devel: cmd. line:1: fatal: or: argument 1 negative value -1 is not 
> > allowed
>
> Good catch. Does the attached patch fix it?
>
> Regards,
> Andy

Attachment: 0002-Eliminate-local-variable-i-in-do_xor.patch
Description: Binary data

Attachment: 0003-Improve-the-initial-value-for-do_and.patch
Description: Binary data


reply via email to

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