Skip to content

Instantly share code, notes, and snippets.

@mattn
Created May 26, 2015 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattn/a286a0fc8d7d639fdd90 to your computer and use it in GitHub Desktop.
Save mattn/a286a0fc8d7d639fdd90 to your computer and use it in GitHub Desktop.
diff -r ca3db36a6ed8 src/os_win32.c
--- a/src/os_win32.c Thu May 14 05:56:09 2015 +0200
+++ b/src/os_win32.c Tue May 26 21:07:27 2015 +0900
@@ -2187,6 +2187,7 @@
COORD BufferCoord;
SMALL_RECT ReadRegion;
WORD Y, Y_incr;
+ BOOL Ret;
if (cb == NULL)
return FALSE;
@@ -2214,6 +2215,7 @@
cb->Buffer = (PCHAR_INFO)alloc(NumCells * sizeof(CHAR_INFO));
if (cb->Buffer == NULL)
return FALSE;
+ ZeroMemory(cb->Buffer, NumCells * sizeof(CHAR_INFO));
}
/*
@@ -2243,16 +2245,29 @@
*/
ReadRegion.Top = Y;
ReadRegion.Bottom = Y + Y_incr - 1;
- if (!ReadConsoleOutput(g_hConOut, /* output handle */
+ /* Windows 9x doesn't work correctly with wide characters. */
+ if (g_PlatformId == VER_PLATFORM_WIN32_NT)
+ Ret = ReadConsoleOutputW(g_hConOut, /* output handle */
cb->Buffer, /* our buffer */
cb->BufferSize, /* dimensions of our buffer */
BufferCoord, /* offset in our buffer */
- &ReadRegion)) /* region to save */
+ &ReadRegion); /* region to save */
+ else
+ Ret = ReadConsoleOutputA(g_hConOut, /* output handle */
+ cb->Buffer, /* our buffer */
+ cb->BufferSize, /* dimensions of our buffer */
+ BufferCoord, /* offset in our buffer */
+ &ReadRegion); /* region to save */
+ if (!Ret)
{
vim_free(cb->Buffer);
cb->Buffer = NULL;
return FALSE;
}
+ /* The region to read is filled by this reading, going next loop
+ * may goes crash because Buffer is over the region. */
+ if (ReadRegion.Bottom > cb->BufferSize.Y)
+ break;
}
return TRUE;
@@ -2274,6 +2289,7 @@
{
COORD BufferCoord;
SMALL_RECT WriteRegion;
+ BOOL Ret;
if (cb == NULL || !cb->IsValid)
return FALSE;
@@ -2316,14 +2332,21 @@
WriteRegion.Top = 0;
WriteRegion.Right = cb->Info.dwSize.X - 1;
WriteRegion.Bottom = cb->Info.dwSize.Y - 1;
- if (!WriteConsoleOutput(g_hConOut, /* output handle */
+ /* Windows 9x doesn't work correctly with wide characters. */
+ if (g_PlatformId == VER_PLATFORM_WIN32_NT)
+ Ret = WriteConsoleOutputW(g_hConOut, /* output handle */
cb->Buffer, /* our buffer */
cb->BufferSize, /* dimensions of our buffer */
BufferCoord, /* offset in our buffer */
- &WriteRegion)) /* region to restore */
- {
+ &WriteRegion); /* region to restore */
+ else
+ Ret = WriteConsoleOutputA(g_hConOut, /* output handle */
+ cb->Buffer, /* our buffer */
+ cb->BufferSize, /* dimensions of our buffer */
+ BufferCoord, /* offset in our buffer */
+ &WriteRegion); /* region to restore */
+ if (!Ret)
return FALSE;
- }
}
return TRUE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment