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

[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.




reply via email to

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