Skip to content

Commit 42c35d9

Browse files
bpo-31966: Fixed WindowsConsoleIO.write() for writing empty data. (GH-5754)
1 parent aef1283 commit 42c35d9

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

‎Lib/test/test_winconsoleio.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ def test_conout_path(self):
121121
else:
122122
self.assertNotIsInstance(f, ConIO)
123123

124+
def test_write_empty_data(self):
125+
with ConIO('CONOUT$', 'w') as f:
126+
self.assertEqual(f.write(b''), 0)
127+
124128
def assertStdinRoundTrip(self, text):
125129
stdin = open('CONIN$', 'r')
126130
old_stdin = sys.stdin
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed WindowsConsoleIO.write() for writing empty data.

‎Modules/_io/winconsoleio.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,9 @@ _io__WindowsConsoleIO_write_impl(winconsoleio *self, Py_buffer *b)
964964
if (!self->writable)
965965
return err_mode("writing");
966966

967+
if (!b->len) {
968+
return PyLong_FromLong(0);
969+
}
967970
if (b->len > BUFMAX)
968971
len = BUFMAX;
969972
else

0 commit comments

Comments
 (0)