Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Apply suggestions from code review
Co-Authored-By: methane <songofacandy@gmail.com>
  • Loading branch information
brettcannon and methane authored Apr 19, 2019
commit c5e610287eca7e20993ba957747752a7f1cdce3c
4 changes: 2 additions & 2 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1311,9 +1311,9 @@ WCharArray_set_value(CDataObject *self, PyObject *value, void *Py_UNUSED(ignored
if (len < 0) {
return -1;
}
// PyUnicode_AsWideChar() returns number of wchars including trailing NUL,
// PyUnicode_AsWideChar() returns number of wchars including trailing null byte,
// when it is called with NULL.
if ((size_t)len-1 > self->b_size/sizeof(wchar_t)) {
if (((size_t)len-1) > self->b_size/sizeof(wchar_t)) {
PyErr_SetString(PyExc_ValueError, "string too long");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth providing in the exception message the provided length and what the max length actually is?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe yes. But this file has similar codes which are not relating to wchar_t APIs. ("bytes string too long").
I want to keep this pull request simple.

result = -1;
goto done;
Expand Down
2 changes: 1 addition & 1 deletion Modules/_ctypes/cfield.c
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length)
if (size < 0) {
return NULL;
}
// PyUnicode_AsWideChar() returns number of wchars including trailing NUL,
// PyUnicode_AsWideChar() returns number of wchars including trailing null byte,
// when it is called with NULL.
size--;
assert(size >= 0);
Expand Down