Skip to content

gh-146615: Fix format specifiers in extension modules#146617

Draft
sunmy2019 wants to merge 1 commit intopython:mainfrom
sunmy2019:gh-146615-2
Draft

gh-146615: Fix format specifiers in extension modules#146617
sunmy2019 wants to merge 1 commit intopython:mainfrom
sunmy2019:gh-146615-2

Conversation

@sunmy2019
Copy link
Copy Markdown
Member

@sunmy2019 sunmy2019 commented Mar 30, 2026

if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
PyErr_Format(PyExc_ValueError,
"size argument should be a positive int less "
"than %ull", ZSTD_CONTENTSIZE_ERROR);
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.

Looks like this was duplicated from #146576. Serhiy asked to add a test in that pull request, so I'd say it'd be best to remove this here and keep the change separate.

else {
if (PyUnicodeWriter_Format(
writer, "unknown error (0x%x)", errcode) < 0) {
writer, "unknown error (0x%lx)", errcode) < 0) {
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.

We can use %#lx.

default:
PyErr_Format(PyExc_ValueError,
"Unsupported TLS/SSL version 0x%x", v);
"Unsupported TLS/SSL version 0x%lx", v);
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.

We can use %#... here too.

I believe that the better fix is to change the type of v to int and update the parsing code above.

Also, cast v to an unsigned type explicitly.

if (result == 0) {
PyErr_Format(PyExc_ValueError,
"Unsupported protocol version 0x%x", v);
"Unsupported protocol version 0x%lx", v);
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.

Same as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants