From: Yongqiang Tian <yqtian668@gmail.com>
To: git@vger.kernel.org
Cc: "Patrick Steinhardt" <ps@pks.im>, "Johannes Sixt" <j6t@kdbg.org>,
"René Scharfe" <l.s.r@web.de>
Subject: [PATCH v2] compat/winansi: fix die_lasterr() argument formatting
Date: Mon, 21 Sep 2026 16:20:53 +1000 [thread overview]
Message-ID: <20260921062114.14450-1-yqtian668@gmail.com> (raw)
In-Reply-To: <20260916042312.35891-1-yqtian668@gmail.com>
During WinANSI initialization, duplicate_handle() reports the handle
when DuplicateHandle() fails. die_lasterr() collects the formatting
arguments in a va_list, but passes that va_list to die_errno() as an
ordinary variadic argument. die_errno() consequently formats part of
the va_list representation instead of the supplied handle, producing
an incorrect fatal message.
The helper also converts GetLastError() to errno, losing the exact
Windows error code.
Remove die_lasterr() and report GetLastError() directly at its four
call sites, following the existing Windows diagnostic style. This
passes the handle to the formatter correctly and preserves the Windows
error code. Keep the existing %li representation of the handle.
With MinGW GCC 13, compat/winansi.o builds with DEVELOPER=1 and the
complete git.exe builds and links.
Signed-off-by: Yongqiang Tian <yqtian668@gmail.com>
---
Changes since v1:
- replace die_lasterr() with direct die() calls;
- preserve exact GetLastError() values instead of mapping them to errno;
- follow the existing Windows diagnostic style and retain %li for the
handle;
- verify compat/winansi.o with DEVELOPER=1 and build and link the
complete git.exe with MinGW GCC 13.
compat/winansi.c | 19 +++++--------------
1 file changed, 5 insertions(+), 14 deletions(-)
diff --git a/compat/winansi.c b/compat/winansi.c
index 3ce1900939..088734a1df 100644
--- a/compat/winansi.c
+++ b/compat/winansi.c
@@ -436,15 +436,6 @@ static void winansi_exit(void)
CloseHandle(hthread);
}
-static void die_lasterr(const char *fmt, ...)
-{
- va_list params;
- va_start(params, fmt);
- errno = err_win_to_posix(GetLastError());
- die_errno(fmt, params);
- va_end(params);
-}
-
#undef dup2
int winansi_dup2(int oldfd, int newfd)
{
@@ -462,8 +453,8 @@ static HANDLE duplicate_handle(HANDLE hnd)
HANDLE hresult, hproc = GetCurrentProcess();
if (!DuplicateHandle(hproc, hnd, hproc, &hresult, 0, TRUE,
DUPLICATE_SAME_ACCESS))
- die_lasterr("DuplicateHandle(%li) failed",
- (long) (intptr_t) hnd);
+ die("DuplicateHandle(%li) failed: %lu",
+ (long) (intptr_t) hnd, GetLastError());
return hresult;
}
@@ -609,16 +600,16 @@ void winansi_init(void)
hwrite = CreateNamedPipeW(name, PIPE_ACCESS_OUTBOUND,
PIPE_TYPE_BYTE | PIPE_WAIT, 1, BUFFER_SIZE, 0, 0, NULL);
if (hwrite == INVALID_HANDLE_VALUE)
- die_lasterr("CreateNamedPipe failed");
+ die("CreateNamedPipe failed: %lu", GetLastError());
hread = CreateFileW(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hread == INVALID_HANDLE_VALUE)
- die_lasterr("CreateFile for named pipe failed");
+ die("CreateFile for named pipe failed: %lu", GetLastError());
/* start console spool thread on the pipe's read end */
hthread = CreateThread(NULL, 0, console_thread, NULL, 0, NULL);
if (!hthread)
- die_lasterr("CreateThread(console_thread) failed");
+ die("CreateThread(console_thread) failed: %lu", GetLastError());
/* schedule cleanup routine */
if (atexit(winansi_exit))
--
2.34.1
next prev parent reply other threads:[~2026-09-21 6:21 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 4:23 [PATCH] compat/winansi: fix die_lasterr() argument formatting Yongqiang Tian
2026-09-16 4:29 ` Junio C Hamano
2026-09-16 6:13 ` Johannes Sixt
2026-09-16 6:33 ` René Scharfe
2026-09-16 7:09 ` Johannes Sixt
2026-09-21 3:00 ` Yongqiang Tian
2026-09-21 4:06 ` Johannes Sixt
2026-09-21 6:20 ` Yongqiang Tian [this message]
2026-09-21 17:18 ` [PATCH v2] " Junio C Hamano
2026-09-21 23:49 ` Yongqiang Tian
2026-09-21 23:47 ` [PATCH v3] " Yongqiang Tian
2026-09-23 4:41 ` Johannes Sixt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260921062114.14450-1-yqtian668@gmail.com \
--to=yqtian668@gmail.com \
--cc=git@vger.kernel.org \
--cc=j6t@kdbg.org \
--cc=l.s.r@web.de \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.