[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gawk substr() problem
From: |
Paul Eggert |
Subject: |
Re: gawk substr() problem |
Date: |
Mon, 18 Nov 2002 14:05:40 -0800 |
> From: Aharon Robbins <address@hidden>
> Date: Mon, 18 Nov 2002 15:31:13 +0200
>
> --lint does catch the negative length case too:
>
> $ gawk --lint 'BEGIN{print substr("abc",2,-2)}'
> gawk: cmd. line:1: warning: substr: length -2 is <= 0
Alas, --lint catches the zero length case as well; this is a bug,
since it's quite reasonable to compute a zero-length substring (e.g.,
when a match is zero length). For example, gawk incorrectly issues a
diagnostic here:
$ gawk --lint 'BEGIN {print substr("x", 1, 0);}' </dev/null
gawk: cmd. line:1: warning: substr: length 0 is <= 0
Also, the diagnostics print the wrong number in many cases due to
floating-point versus integer anomalies. E.g., on a 32-bit host::
$ gawk --lint 'BEGIN {print substr("x", 1, 4294967294);}' </dev/null
gawk: cmd. line:1: warning: substr: length -2 at start index 1 exceeds length
of first argument (1)
x
$ gawk --lint 'BEGIN {print substr("x", 1, 1e300);}' </dev/null
gawk: cmd. line:1: warning: substr: length -1 at start index 1 exceeds length
of first argument (1)
x
$ gawk --lint 'BEGIN {print substr("x", 1, 1e300*1e300 - 1e300*1e300);}'
</dev/null
gawk: cmd. line:1: warning: substr: non-integer length NaN will be truncated
gawk: cmd. line:1: warning: substr: length 2147483647 at start index 1
exceeds length of first argument (1)
x
- gawk substr() problem, Stepan Kasal, 2002/11/12
- Re: gawk substr() problem, Aharon Robbins, 2002/11/19
- Re: gawk substr() problem, Aharon Robbins, 2002/11/19
- Re: gawk substr() problem, Aharon Robbins, 2002/11/21
- Re: gawk substr() problem, Aharon Robbins, 2002/11/22