summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2002-03-08 05:43:32 (GMT)
committerTim Peters <tim.peters@gmail.com>2002-03-08 05:43:32 (GMT)
commitc9ffa068d1d1dc93f620994a532f219a4be08385 (patch)
tree5fcedce005ed23f1afd1eb221ce6a71dfc0bd5fb /Modules
parent02d2212c8ebadac24272541f2607a784415c606e (diff)
downloadcpython-c9ffa068d1d1dc93f620994a532f219a4be08385.zip
cpython-c9ffa068d1d1dc93f620994a532f219a4be08385.tar.gz
cpython-c9ffa068d1d1dc93f620994a532f219a4be08385.tar.bz2
SF bug 515943: searching for data with \0 in mmap.
mmap_find_method(): this obtained the string to find via s#, but it ignored its length, acting as if it were \0-terminated instead. Someone please run on Linux too (the extended test_mmap works on Windows). Bugfix candidate.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/mmapmodule.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index cd13914..3164a27 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -251,20 +251,16 @@ mmap_find_method(mmap_object *self,
start = 0;
else if ((size_t)start > self->size)
start = self->size;
- p = self->data + start;
- while (p < e) {
- char *s = p;
- char *n = needle;
- while ((s<e) && (*n) && !(*s-*n)) {
- s++, n++;
- }
- if (!*n) {
+ for (p = self->data + start; p + len <= e; ++p) {
+ int i;
+ for (i = 0; i < len && needle[i] == p[i]; ++i)
+ /* nothing */;
+ if (i == len) {
return Py_BuildValue (
"l",
(long) (p - self->data));
}
- p++;
}
return Py_BuildValue ("l", (long) -1);
}