[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gawk substr() problem
From: |
Stepan Kasal |
Subject: |
gawk substr() problem |
Date: |
Tue, 12 Nov 2002 15:55:17 +0100 |
User-agent: |
Mutt/1.2.5.1i |
Hello,
I've discovered a bug in GNU awk (tried with 3.1.1 and 3.0.4):
substr(str, start, len)
- POSIX doesn't say what to do if `start' is less or equal to 0.
I'd say it should be an error. GNU awk manual says that the null
string is returned.
when you call substr() in gawk with start <= 0, it behaves as if start
was 0, which differs from the above specification.
$ gawk-3.1.1/gawk 'BEGIN{print substr("abc",-5,2)}'
ab
$
Wouldn't it be best to fix both docs and code and issue an error message
if `start' is <= 0.
It would be particularily helpful for start == 0 as this indicates that
the programmer has forgotten that awk strings are indexed from 1.
(Willing to make a patch, when the king's ruling is known. :-)
- POSIX doesn't say what to do if `len' is negative.
GNU awk returns the null string.
This is not a bug but a feature request: wouldn't it be better to issue
an error message instead?
Have a nice day,
Stepan