summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2010-02-27 18:32:49 +0900
committerKaz Kylheku <kaz@kylheku.com>2010-02-27 18:32:49 +0900
commit0bad0c321d51352bfb68c3759c7fd78489e7e254 (patch)
treeb3fdd39859669e02c6a57299a2e722466a071dd7 /lib.c
parentf2b8e780f0e3c0634644887639f97adbf7c1c9dc (diff)
downloadtxr-0bad0c321d51352bfb68c3759c7fd78489e7e254.tar.gz
txr-0bad0c321d51352bfb68c3759c7fd78489e7e254.tar.bz2
txr-0bad0c321d51352bfb68c3759c7fd78489e7e254.zip
* lib.c (search_str): Bugfix for empty haystack case: checks for end
of string must use postincrement on the index, otherwise the access goes past the null terminator.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib.c b/lib.c
index 6ce2a1f4..1d073a29 100644
--- a/lib.c
+++ b/lib.c
@@ -882,7 +882,7 @@ val search_str(val haystack, val needle, val start_num, val from_end)
pos = f - h;
else
pos = -1;
- } while (pos != -1 && (good = pos) != -1 && from_end && h[++start]);
+ } while (pos != -1 && (good = pos) != -1 && from_end && h[start++]);
} else {
size_t ln = c_num(length_str(needle));
@@ -892,7 +892,7 @@ val search_str(val haystack, val needle, val start_num, val from_end)
if (!wcsncmp(h + start, n, ln))
good = start;
- } while (h[++start] && (from_end || good == -1));
+ } while (h[start++] && (from_end || good == -1));
}
return (good == -1) ? nil : num(good);
}