Skip to content

Commit

Permalink
bpo-31966: Fixed WindowsConsoleIO.write() for writing empty data. (GH…
Browse files Browse the repository at this point in the history
…-5754)

(cherry picked from commit 42c35d9)

Co-authored-by: Serhiy Storchaka <[email protected]>
  • Loading branch information
miss-islington and serhiy-storchaka authored Feb 24, 2018
1 parent 46632f4 commit e49bf0f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Lib/test/test_winconsoleio.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ def test_conout_path(self):
else:
self.assertNotIsInstance(f, ConIO)

def test_write_empty_data(self):
with ConIO('CONOUT$', 'w') as f:
self.assertEqual(f.write(b''), 0)

def assertStdinRoundTrip(self, text):
stdin = open('CONIN$', 'r')
old_stdin = sys.stdin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed WindowsConsoleIO.write() for writing empty data.
3 changes: 3 additions & 0 deletions Modules/_io/winconsoleio.c
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,9 @@ _io__WindowsConsoleIO_write_impl(winconsoleio *self, Py_buffer *b)
if (!self->writable)
return err_mode("writing");

if (!b->len) {
return PyLong_FromLong(0);
}
if (b->len > BUFMAX)
len = BUFMAX;
else
Expand Down

0 comments on commit e49bf0f

Please sign in to comment.