Skip to content
Merged
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
Update posixmodule.c
  • Loading branch information
Wulian233 authored May 2, 2025
commit 87ab5aa5812242aa0b1f685d137475dd67c2995f
4 changes: 2 additions & 2 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4189,8 +4189,8 @@ posix_getcwd(int use_bytes)
/* If the buffer is large enough, len does not include the
terminating \0. If the buffer is too small, len includes
the space needed for the terminator. */
if ((size_t)len >= Py_ARRAY_LENGTH(wbuf)) {
if (len <= PY_SSIZE_T_MAX / sizeof(wchar_t)) {
if (len >= Py_ARRAY_LENGTH(wbuf)) {
if ((Py_ssize_t)len <= PY_SSIZE_T_MAX / sizeof(wchar_t)) {

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.

This indeed fixes the warning. IMHO, that's the most pragmatic fix. We could be fancy and do some #if on sizeof(Py_ssize_t), etc, but I don't think it is worth the hassle.

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.

sizeof doesn't work in preprocessor checks anyway.

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.

Yeah, I meant something like we do with SIZEOF_SIZE_T, but did not want to elaborate about it in great detail, because IMHO it isn't worth the churn?

wbuf2 = PyMem_RawMalloc(len * sizeof(wchar_t));
}
else {
Expand Down