Andrew Nguyen : kernel32: Ensure that WriteConsoleW succeeds with an empty input buffer.

Alexandre Julliard julliard at winehq.org
Mon Jan 19 08:58:35 CST 2009


Module: wine
Branch: master
Commit: 976d5cae8d58b29564cd802b4330ad211557f518
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=976d5cae8d58b29564cd802b4330ad211557f518

Author: Andrew Nguyen <arethusa26 at gmail.com>
Date:   Sun Jan 18 23:52:11 2009 -0600

kernel32: Ensure that WriteConsoleW succeeds with an empty input buffer.

---

 dlls/kernel32/console.c       |    2 ++
 dlls/kernel32/tests/console.c |   41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/dlls/kernel32/console.c b/dlls/kernel32/console.c
index a872b1f..d247e1b 100644
--- a/dlls/kernel32/console.c
+++ b/dlls/kernel32/console.c
@@ -2057,6 +2057,8 @@ BOOL WINAPI WriteConsoleW(HANDLE hConsoleOutput, LPCVOID lpBuffer, DWORD nNumber
 	!GetConsoleScreenBufferInfo(hConsoleOutput, &csbi))
 	return FALSE;
 
+    if (!nNumberOfCharsToWrite) return TRUE;
+
     if (mode & ENABLE_PROCESSED_OUTPUT)
     {
 	unsigned int	i;
diff --git a/dlls/kernel32/tests/console.c b/dlls/kernel32/tests/console.c
index a90fe70..eb51f7a 100644
--- a/dlls/kernel32/tests/console.c
+++ b/dlls/kernel32/tests/console.c
@@ -173,6 +173,45 @@ static void testCursorInfo(HANDLE hCon)
        ERROR_INVALID_ACCESS, GetLastError());
 }
 
+static void testEmptyWrite(HANDLE hCon)
+{
+    COORD		c;
+    DWORD		len;
+    const char* 	mytest = "";
+
+    c.X = c.Y = 0;
+    ok(SetConsoleCursorPosition(hCon, c) != 0, "Cursor in upper-left\n");
+
+    len = -1;
+    ok(WriteConsole(hCon, NULL, 0, &len, NULL) != 0 && len == 0, "WriteConsole\n");
+    okCURSOR(hCon, c);
+
+    /* Passing a NULL lpBuffer with sufficiently large non-zero length succeeds
+     * on native Windows and result in memory-like contents being written to
+     * the console. Calling WriteConsoleW like this will crash on Wine. */
+    if (0)
+    {
+        len = -1;
+        ok(!WriteConsole(hCon, NULL, 16, &len, NULL) && len == -1, "WriteConsole\n");
+        okCURSOR(hCon, c);
+
+        /* Cursor advances for this call. */
+        len = -1;
+        ok(WriteConsole(hCon, NULL, 128, &len, NULL) != 0 && len == 128, "WriteConsole\n");
+    }
+
+    len = -1;
+    ok(WriteConsole(hCon, mytest, 0, &len, NULL) != 0 && len == 0, "WriteConsole\n");
+    okCURSOR(hCon, c);
+
+    /* WriteConsole does not halt on a null terminator and is happy to write
+     * memory contents beyond the actual size of the buffer. */
+    len = -1;
+    ok(WriteConsole(hCon, mytest, 16, &len, NULL) != 0 && len == 16, "WriteConsole\n");
+    c.X += 16;
+    okCURSOR(hCon, c);
+}
+
 static void testWriteSimple(HANDLE hCon)
 {
     COORD		c;
@@ -407,6 +446,8 @@ static void testWrite(HANDLE hCon, COORD sbSize)
     /* FIXME: should in fact insure that the sb is at least 10 character wide */
     ok(SetConsoleTextAttribute(hCon, TEST_ATTRIB), "Setting default text color\n");
     resetContent(hCon, sbSize, FALSE);
+    testEmptyWrite(hCon);
+    resetContent(hCon, sbSize, FALSE);
     testWriteSimple(hCon);
     resetContent(hCon, sbSize, FALSE);
     testWriteNotWrappedNotProcessed(hCon, sbSize);




More information about the wine-cvs mailing list