Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7983869

Browse files
committed
handle mmap_write_byte_method
1 parent f97d213 commit 7983869

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Fix crashes in :func:`mmap.read`, :func:`mmap.read_byte` and :func:`mmap.write` on Windows when the underlying file operation raises errors.
1+
Fix crashes in :func:`mmap.read`, :func:`mmap.read_byte`, :func:`mmap.write`
2+
and :func:`mmap.write_byte` on Windows when the underlying file operation raises errors.

Modules/mmapmodule.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,18 @@ mmap_write_byte_method(mmap_object *self,
511511
return NULL;
512512

513513
CHECK_VALID(NULL);
514-
if (self->pos < self->size) {
515-
self->data[self->pos++] = value;
516-
Py_RETURN_NONE;
517-
}
518-
else {
514+
if (self->pos >= self->size) {
519515
PyErr_SetString(PyExc_ValueError, "write byte out of range");
520516
return NULL;
521517
}
518+
519+
if (safe_memcpy(self->data + self->pos, value, 1) < 0) {
520+
return NULL;
521+
}
522+
else {
523+
self->pos++;
524+
Py_RETURN_NONE;
525+
}
522526
}
523527

524528
static PyObject *

0 commit comments

Comments
 (0)