Skip to content

os.truncate() ignores _chsize_s() errors on Windows #159630

Open

Description

@aisk

Bug report

cpython/Modules/posixmodule.c

Lines 13651 to 13654 in a2c999b

result = _chsize_s(fd, length);
close(fd);
if (result < 0)
errno = result;

_chsize_s() returns 0 on success and a positive errno value on failure according to MS's document: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/chsize-s?view=msvc-170#return-value, but the code checks result < 0, so failures are silently ignored.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions