mingw: consider that UNICODE_STRING::Length counts bytes
authorMax Kirillov <max@max630.net>
Mon, 19 Dec 2016 21:32:00 +0000 (23:32 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 20 Dec 2016 17:04:57 +0000 (09:04 -0800)
UNICODE_STRING::Length field means size of buffer in bytes[1],
despite of buffer itself being array of wchar_t. Because of that
terminating zero is placed twice as far. Fix it.

[1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa380518.aspx

Signed-off-by: Max Kirillov <max@max630.net>
Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
compat/winansi.c
index 3be60ce1c6fc0b5a6d96fdbe1101ed99e28b3585..6b4f736fdcc16d979ad3e8047a34e98afc33ddda 100644 (file)
@@ -553,7 +553,7 @@ static void detect_msys_tty(int fd)
                        buffer, sizeof(buffer) - 2, &result)))
                return;
        name = nameinfo->Name.Buffer;
-       name[nameinfo->Name.Length] = 0;
+       name[nameinfo->Name.Length / sizeof(*name)] = 0;
 
        /* check if this could be a MSYS2 pty pipe ('msys-XXXX-ptyN-XX') */
        if (!wcsstr(name, L"msys-") || !wcsstr(name, L"-pty"))