Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Use Py_SIZE() in s_set() of cfield.c
  • Loading branch information
shihai1991 committed Feb 9, 2020
commit 02f0de2a5802105150f4a51eb9a13f4e3ea267f4
5 changes: 3 additions & 2 deletions Modules/_ctypes/cfield.c
Original file line number Diff line number Diff line change
Expand Up @@ -1293,8 +1293,7 @@ s_set(void *ptr, PyObject *value, Py_ssize_t length)
return NULL;
}

data = PyBytes_AS_STRING(value);
size = strlen(data); /* XXX Why not Py_SIZE(value)? */
size = Py_SIZE(value);
if (size < length) {
/* This will copy the terminating NUL character
* if there is space for it.
Expand All @@ -1306,6 +1305,8 @@ s_set(void *ptr, PyObject *value, Py_ssize_t length)
size, length);
return NULL;
}

data = PyBytes_AS_STRING(value);
/* Also copy the terminating NUL character if there is space */
memcpy((char *)ptr, data, size);

Expand Down