]> granicus.if.org Git - python/commitdiff
bpo-31966: Fixed WindowsConsoleIO.write() for writing empty data. (GH-5754)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 24 Feb 2018 17:39:18 +0000 (09:39 -0800)
committerGitHub <noreply@github.com>
Sat, 24 Feb 2018 17:39:18 +0000 (09:39 -0800)
(cherry picked from commit 42c35d9c0c8175332f50fbe034a001fe52f057b9)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/test_winconsoleio.py
Misc/NEWS.d/next/Windows/2018-02-19-13-54-42.bpo-31966._Q3HPb.rst [new file with mode: 0644]
Modules/_io/winconsoleio.c

index 656483cf1621c7b5494b22110a5e1a18dee5dba9..a78fa4d7d919fffb8846651523120b9956c74f56 100644 (file)
@@ -121,6 +121,10 @@ class WindowsConsoleIOTests(unittest.TestCase):
             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
diff --git a/Misc/NEWS.d/next/Windows/2018-02-19-13-54-42.bpo-31966._Q3HPb.rst b/Misc/NEWS.d/next/Windows/2018-02-19-13-54-42.bpo-31966._Q3HPb.rst
new file mode 100644 (file)
index 0000000..042a4d8
--- /dev/null
@@ -0,0 +1 @@
+Fixed WindowsConsoleIO.write() for writing empty data.
index 30d1c767afcf74d99bd47e3c2da7b909975e63a8..b85c11b3405a73a1e7501ef07559038958989d15 100644 (file)
@@ -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