8000 gh-76961: Fix the PEP3118 format string for ctypes.Structure by eric-wieser · Pull Request #5561 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-76961: Fix the PEP3118 format string for ctypes.Structure #5561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 5, 2023
Prev Previous commit
Apply suggestions from code review
  • Loading branch information
eric-wieser authored Feb 5, 2023
commit 26311aecd38ae115f88b38708bc65eacbbcab651
7 changes: 5 additions & 2 deletions Modules/_ctypes/stgdict.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ MakeAnonFields(PyObject *type)
}

/*
Append {padding}x to the PEP3118 format string.
Allocate a memory block for a pep3118 format string, copy prefix (if
non-null) into it and append `{padding}x` to the end.
Returns NULL on failure, with the error indicator set.
*/
char *
_ctypes_alloc_format_padding(const char *prefix, Py_ssize_t padding)
Expand All @@ -353,7 +355,8 @@ _ctypes_alloc_format_padding(const char *prefix, Py_ssize_t padding)
return _ctypes_alloc_format_string(prefix, "x");
}

sprintf(buf, "%zdx", padding);
int ret = PyOS_snprintf(buf, sizeof(buf), "%zdx", padding);
assert(0 <= ret && ret < sizeof(buf));
return _ctypes_alloc_format_string(prefix, buf);
}

Expand Down
0