git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] compat/winansi: fix die_lasterr() argument formatting

From
YTYongqiang Tian <yqtian668@gmail.com>
Date
Sep 21, 2026, 23:49 UTC
Message-ID
<CAEs0Zp7M3qtAznHj_0yyab7e0xDLWjd3+Ja1Yr3GfEPJZQr+Vw@mail.gmail.com>
In-Reply-To
<xmqqwlsemsjt.fsf@gitster.g>
Hi Junio,
Thank you very much for the suggestion.
> Unless the set-up to test this change needs some special care, we
> usually do not write such a thing in our proposed log message.

Oh, I see. I'll follow this convention. I've moved the build validation details below the separator in v3.

> I would probably have added a Helped-by:
> to credit j6t, though.

I've added Helped-by trailers for both Johannes Sixt and René Scharfe. I'm grateful to both for their guidance on this fix.

> Is that a change, meaning v1 was sent without building, linking and
> testing?

Ah, sorry for the confusion. v1 was also compiled with MinGW and checked with a Win64 probe under Wine. I should have listed the v2 validation separately rather than under "Changes since v1".

I've sent v3 separately with these message updates and no code changes.
Thank you very much!

Thanks, Yongqiang

On Tue, 22 Sept 2026 at 03:18, Junio C Hamano <gitster@pobox.com> wrote:
Show 69 quoted lines
>
> Yongqiang Tian <yqtian668@gmail.com> writes:
>
> > 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.
>
> Interesting.
>
> It's a shame that nobody noticed the broken calling sequence since
> the bogosity was first introduced into the codebase at eac14f8909
> (Win32: Thread-safe windows console output, 2012-01-14).
>
> > 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.
>
> OK.
>
> > With MinGW GCC 13, compat/winansi.o builds with DEVELOPER=1 and the
> > complete git.exe builds and links.
>
> I am puzzled here.  What's the relevance of these two lines?
>
> Are you telling us that how you have built and tested the patch?
> Unless the set-up to test this change needs some special care, we
> usually do not write such a thing in our proposed log message.
>
> > 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;
>
> Good collaboration.  If I were doing this commit, judging from the
> discussion on v1 iteration, I would probably have added a Helped-by:
> to credit j6t, though.
>
> > - verify compat/winansi.o with DEVELOPER=1 and build and link the
> >   complete git.exe with MinGW GCC 13.
>
> Is that a change, meaning v1 was sent without building, linking and
> testing?  Improving on that is a very welcome thing ;-).
>
> >  compat/winansi.c | 19 +++++--------------
> >  1 file changed, 5 insertions(+), 14 deletions(-)
>
> Nice.
>
> > -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);
> > -}
>
> Very good to see this go.
Previous: Junio C HamanoNext: Yongqiang Tian
Message 10 of 12 in “compat/winansi: fix die_lasterr() argument formatting”
  1. compat/winansi: fix die_lasterr() argument formattingYongqiang Tian, Sep 16, 2026
  2. Junio C HamanoSep 16, 2026
  3. Johannes SixtSep 16, 2026
  4. René ScharfeSep 16, 2026
  5. Johannes SixtSep 16, 2026
  6. Yongqiang TianSep 21, 2026
  7. Johannes SixtSep 21, 2026
  8. compat/winansi: fix die_lasterr() argument formattingYongqiang Tian, Sep 21, 2026
  9. Junio C HamanoSep 21, 2026
  10. Yongqiang TianSep 21, 2026
  11. compat/winansi: fix die_lasterr() argument formattingYongqiang Tian, Sep 21, 2026
  12. Johannes SixtSep 23, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.