[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gawk substr() problem
From: |
Aharon Robbins |
Subject: |
Re: gawk substr() problem |
Date: |
Tue, 19 Nov 2002 15:37:54 +0200 |
Greetings. Re this:
> From: "Paul Eggert" <address@hidden>
> Date: Mon, 18 Nov 2002 14:05:40 -0800
> To: address@hidden
> CC: address@hidden
> Subject: Re: gawk substr() problem
>
> 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
See patch below that fixes this.
> $ 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
I get different results than this on my RH 7.2 GNU/Linux system. In any case,
this
patch should help.
Arnold
-----------------------------------
Tue Nov 19 15:33:55 2002 Arnold D. Robbins <address@hidden>
* builtin.c (do_substr): Use %lu in warnings instead of %d.
*** ../gawk-3.1.1/builtin.c Tue Apr 16 14:40:31 2002
--- builtin.c Tue Nov 19 15:33:50 2002
***************
*** 1218,1230 ****
if ((indx + length) > t1->stlen) {
if (do_lint)
lintwarn(
! _("substr: length %d at start index %d exceeds length of first argument
(%d)"),
length, indx+1, t1->stlen);
length = t1->stlen - indx;
}
if (indx >= t1->stlen) {
if (do_lint)
! lintwarn(_("substr: start index %d is past end of
string"),
indx+1);
free_temp(t1);
return Nnull_string;
--- 1225,1237 ----
if ((indx + length) > t1->stlen) {
if (do_lint)
lintwarn(
! _("substr: length %lu at start index %lu exceeds length of first
argument (%lu)"),
length, indx+1, t1->stlen);
length = t1->stlen - indx;
}
if (indx >= t1->stlen) {
if (do_lint)
! lintwarn(_("substr: start index %lu is past end of
string"),
indx+1);
free_temp(t1);
return Nnull_string;