Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7983869

Browse filesBrowse files
committed
handle mmap_write_byte_method
1 parent f97d213 commit 7983869
Copy full SHA for 7983869

File tree

Expand file treeCollapse file tree

2 files changed

+11
-6
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+11
-6
lines changed
+2-1Lines 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

Copy file name to clipboardExpand all lines: Modules/mmapmodule.c
+9-5Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.