[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug: gawk 3.0 fails to index(.,"")
From: |
Aharon Robbins |
Subject: |
Re: Bug: gawk 3.0 fails to index(.,"") |
Date: |
Sun, 1 Jul 2001 19:22:41 +0300 |
This was posted in comp.lang.awk.
> From: Lash Canino <address@hidden>
> Newsgroups: comp.lang.awk
> Subject: Bug: gawk 3.0 fails to index(.,"")
> Date: 30 Jun 2001 11:39:08 +0200
>
> No string does contain the null string in GNU Awk 3.0!
>
> Just consider this script:
>
> BEGIN{print index("string","")}
>
> It says 0.
>
> Now substitute match( for index(: It says 1. OTOH, this
> substitution should not change the meaning of the script.
> "string" might even be "" (the null string); then, the null
> string does not contain itself.
>
> Mawk says 1 both times, as any awk should, if only because
> AKW88 tells us so.
>
> Does GNU Awk 3.1 fix this? (I observed this in both 3.0.3
> and 3.0.6.)
>
> Thank you,
>
> Lash
After consultation with other awk implementors, I've decided it's a
bug. Below is an unofficial patch relative to gawk 3.1.0. It will
probably drop into 3.0.6 too.
Arnold
-------------------------------------------------
*** ../gawk-3.1.0/builtin.c Tue Feb 27 12:14:24 2001
--- builtin.c Sun Jul 1 19:14:37 2001
***************
*** 231,236 ****
--- 231,246 ----
l2 = s2->stlen;
ret = 0;
+ /*
+ * Icky special case, index(foo, "") should return 1,
+ * since both bwk awk and mawk do, and since match("foo", "")
+ * returns 1. This makes index("", "") work, too, fwiw.
+ */
+ if (l2 == 0) {
+ ret = 1;
+ goto out;
+ }
+
/* IGNORECASE will already be false if posix */
if (IGNORECASE) {
while (l1 > 0) {
***************
*** 257,262 ****
--- 267,273 ----
p1++;
}
}
+ out:
free_temp(s1);
free_temp(s2);
return tmp_number((AWKNUM) ret);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Bug: gawk 3.0 fails to index(.,""),
Aharon Robbins <=