[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: |
Tue, 19 Nov 2002 01:39:50 -0800 (PST) |
> Date: Tue, 19 Nov 2002 09:37:12 +0100
> From: Stepan Kasal <address@hidden>
> > Alas, --lint catches the zero length case as well; this is a bug,
> > since it's quite reasonable to compute a zero-length substring ...
>
> > $ gawk --lint 'BEGIN {print substr("x", 1, 0);}' </dev/null
> > gawk: cmd. line:1: warning: substr: length 0 is <= 0
>
> IMHO it's very similar to
>
> > $ gawk --lint 'BEGIN {print substr("x", 1, 4);}' </dev/null
> > gawk: cmd. line:1: warning: substr: length 4 at start index 1 exceeds
> > length of first argument (1)
No, it's not similar. It's quite reasonable for a program to do the
former, but the latter is less resonable.
For example, the following is quite reasonable code:
match(s, "^[0-9]*")
leading_digits_if_any = substr(s, RSTART, RLENGTH)
but this code generates the warning if s happens to have no leading
digits.
- 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