mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
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.
This commit is contained in:
parent
02d2212c8e
commit
c9ffa068d1
2 changed files with 30 additions and 9 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue