From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fhigh-b8-smtp.messagingengine.com (fhigh-b8-smtp.messagingengine.com [202.12.124.159]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 937223AF64D for ; Wed, 16 Sep 2026 04:29:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.159 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789532963; cv=none; b=NRL2eqgK9ph+kmoUQ1MdjQaZcFlqipqUuAqcch22BeWjvCLOXv7LFTJQgo9+dhO0SAxySuszp2CvdA8IjF1XZHO7S7SjHpCfr78dYvJ6vdczYe2oo5WURsfWNV4COybtbL3DyLW2lS5AuaYPd+fKvFpoAxQQIJKnGmPFbHtl8+k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789532963; c=relaxed/simple; bh=h6oqt3n/SID8sdKmHVJEpoyGFI3QDmHIYk4eo/YbE0A=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=I9rgAdBOTdn9GOf6kzrmB+V1y4SJKBVXSpOZczX/9THqBB9OWll701vfM60xORpXsFhcBUaXTjyZVI3Mv6ZAVrZ4IOySq4KJd/lQGSv7I5T7Pv7SdJZ2Loif7YlVTSnT2eSUBNfyAoOqXS8mBBbhzbQ0URTYvUZjteQSm/c/Ogs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b=sV370VcM; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=wW86+awo; arc=none smtp.client-ip=202.12.124.159 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b="sV370VcM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="wW86+awo" Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfhigh.stl.internal (Postfix) with ESMTP id 839867A00B9; Wed, 16 Sep 2026 00:29:20 -0400 (EDT) Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-03.internal (MEProxy); Wed, 16 Sep 2026 00:29:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1789532960; x=1789619360; bh=wIgLexrhuo O9B99AFI3nvvKlMOlWH051xjovpa8EKLA=; b=sV370VcM2lyjHgHADhuFFAWrX9 vvPXyQ03857CdGNnE+/fa/G6QlVdRmGQK55nk27XmCztM/hI82+uo/97X27RV1Kw FAUSFexXKhxgDQ/dVqDrU78nUihXLvH37gs9SDU5RZGOW7xuFCA87RzLG6jBjbeH qJ2tNKqv1gfj/db6jbiNYwj/nBc/8+kDI5s1mcR4Q3Qc0r5ThyhUBbZSw5ve9vO3 iWfGMYhQBfT1BcJNS0ZdnImdxFkC/P1skA0fawKCo1and9AiPM1CQefRZR+7iiWU vgfhicb5a4c3qEojX7NPa0m22LTmMThCweLPo+wLtPq7BHapuFqPpXc/N/WA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1789532960; x=1789619360; bh=wIgLexrhuoO9B99AFI3nvvKlMOlWH051x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Cuw4uIQZJEUfXrmHwtAFw X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 16 Sep 2026 00:29:19 -0400 (EDT) From: Junio C Hamano To: Yongqiang Tian Cc: git@vger.kernel.org, Patrick Steinhardt , Johannes Sixt , Johannes Schindelin Subject: Re: [PATCH] compat/winansi: fix die_lasterr() argument formatting In-Reply-To: <20260916042312.35891-1-yqtian668@gmail.com> (Yongqiang Tian's message of "Wed, 16 Sep 2026 14:23:12 +1000") References: <20260916042312.35891-1-yqtian668@gmail.com> Date: Tue, 15 Sep 2026 21:29:18 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Yongqiang Tian writes: > During WinANSI initialization, duplicate_handle() reports the handle > when DuplicateHandle() fails: > > die_lasterr("DuplicateHandle(%li) failed", ...); > ... I do not know about Patrick, but I do not do Windows, so please do not Cc: me a patch that is primarily about Windows portability. I'll add two whose with contributions much greater than I have in the area to Cc: list. Thanks. > 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 the representation of the va_list > instead of the supplied handle, producing an incorrect fatal message. > The other current callers pass fixed strings and are unaffected. > > Git does not provide a va_list-taking variant of die_errno(), so format > the caller's arguments separately with strbuf_vaddf(). This consumes the > original va_list correctly and produces the complete diagnostic prefix, > including the handle supplied by duplicate_handle(). > > Save GetLastError() before formatting because calls made while growing > the strbuf may change the thread's Windows error value. Convert the > saved value to errno only after formatting, then pass the completed > message to die_errno() through a literal "%s". This prevents any percent > characters in the formatted message from being interpreted a second > time, while allowing die_errno() to append the corresponding system > error and terminate as before. > > The updated compat/winansi.c compiles with MinGW GCC 13. A Win64 probe > under Wine prints a value derived from the va_list before this change > and the supplied integer afterward. > > Signed-off-by: Yongqiang Tian > --- > compat/winansi.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/compat/winansi.c b/compat/winansi.c > index 3ce190093..5547192a2 100644 > --- a/compat/winansi.c > +++ b/compat/winansi.c > @@ -7,6 +7,7 @@ > #define DISABLE_SIGN_COMPARE_WARNINGS > > #include "../git-compat-util.h" > +#include "../strbuf.h" > #include > #include > #include "win32.h" > @@ -438,11 +439,15 @@ static void winansi_exit(void) > > static void die_lasterr(const char *fmt, ...) > { > + DWORD err = GetLastError(); > + struct strbuf message = STRBUF_INIT; > va_list params; > + > va_start(params, fmt); > - errno = err_win_to_posix(GetLastError()); > - die_errno(fmt, params); > + strbuf_vaddf(&message, fmt, params); > va_end(params); > + errno = err_win_to_posix(err); > + die_errno("%s", message.buf); > } > > #undef dup2