DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 4B7GZ4Pk105576
Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com
Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 4B7GZ4Pk105576
Authentication-Results: delorie.com;
	dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=ql+GvI8X
X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 14AF53858423
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1733589303;
	bh=99joJCPjy4po8CvrnMWbH+7Yoql/mxnuz32dptf1th8=;
	h=Date:Subject:To:References:Cc:In-Reply-To:List-Id:
	 List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe:
	 From:Reply-To:From;
	b=ql+GvI8XYCsJUUe/4f+5X8PbpCALppFRfWPpOtt34bZCL9xfhdfQ/5nhGH33GITH1
	 D59uyXHuziisQTWQdTBzlZ1jHHz08C65twOyyV4cIRaAjOI2g4joCbzUi53QC/2f7g
	 RGqpiXUY704pTCJbTnHtMg4JTjFsCPNS+yKKpSwA=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 46163385841C
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 46163385841C
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733589238; cv=none;
 b=GIaCSEiwCrkotBgYZUOJUk6TO3GxysRjX2D5c8HyUG5nnM+pnCmefR5vUgzSfaN/QoUWzFndzQXc2SRfOdKS3Oq4i72Ca4KuRPOEfeYMeBeToiidAirx48lkdgvDrI2XTSYKhvW6i07eV2KvhZB5DAVInMm0p6rgfpzW1mJ1X/U=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
 t=1733589238; c=relaxed/simple;
 bh=GQ9GB9zDGIZsQ7gTYX1FfA0aTpSgLavnLBG/JwXecDY=;
 h=Message-ID:Date:MIME-Version:Subject:To:From;
 b=D2SeS5uQ37idh5wEbCkx2Ok9DCicm2Mk8M1pknLaquHS/AUk+Ep9j0JZ2LqTPpsiJA2l7NC4UfPwD/Uqi0U8QugGpjksDVerbDJ/eqBQM+ijqcyE0+xmWBLf1a3MTyDd040dUQ74nrTr9oGsYqEvB0ISGI9EkfYeOwM7Ea2F7jM=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 46163385841C
X-SNCR-Rigid: 674901FF00E38BFD
X-Originating-IP: [86.143.185.89]
X-OWM-Source-IP: 86.143.185.89
X-OWM-Env-Sender: jon.turney@dronecode.org.uk
X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgeefuddrjedugdekkecutefuodetggdotefrodftvfcurfhrohhfihhlvgemuceutffkvffkuffjvffgnffgvefqofdpqfgfvfenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepkfffgggfuffvfhfhvegjtgfgsehtjeertddtvdejnecuhfhrohhmpeflohhnucfvuhhrnhgvhicuoehjohhnrdhtuhhrnhgvhiesughrohhnvggtohguvgdrohhrghdruhhkqeenucggtffrrghtthgvrhhnpeeggeeuteeigeeikefgheethfetuefhtdegieeikeehteehfeefvdeuffdtveejffenucffohhmrghinhepshhouhhrtggvfigrrhgvrdhorhhgnecukfhppeekiedrudegfedrudekhedrkeelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehhvghloheplgduledvrdduieekrddurddutdelngdpihhnvghtpeekiedrudegfedrudekhedrkeelpdhmrghilhhfrhhomhepjhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukhdprhgvvhfkrfephhhoshhtkeeiqddugeefqddukeehqdekledrrhgrnhhgvgekiedqudegfedrsghttggvnhhtrhgrlhhplhhushdrtghomhdprghuthhhpghushgvrhepjhhonhhtuhhrnhgvhiessghtihhnthgvrhhnvghtrdgtohhmpdhgvghokffrpefiuedpoffvtefjohhsthepsghtphhrughrghhotddtkedpnhgspghrtghpthhtohepvddprhgtphht
 thhopefmvghithhhrdfurdfvhhhomhhpshhonhesghhmrghilhdrtghomhdprhgtphhtthhopegthihgfihinhestgihghifihhnrdgtohhm
X-RazorGate-Vade-Verdict: clean 0
X-RazorGate-Vade-Classification: clean
X-VadeSecure-score: verdict=clean score=0/300, class=clean
Message-ID: <295c1185-c839-40df-80a7-2a59a4d742ca@dronecode.org.uk>
Date: Sat, 7 Dec 2024 16:33:48 +0000
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: Bug in handling of "1$", "2$" in printf format
To: Keith Thompson <Keith.S.Thompson@gmail.com>
References: <CAAHpriPTSi-ji2xqX_yhNbtkdX_BxBr=tzchN=Gxk4dXg3kbAw@mail.gmail.com>
Content-Language: en-US
Cc: cygwin@cygwin.com
In-Reply-To: <CAAHpriPTSi-ji2xqX_yhNbtkdX_BxBr=tzchN=Gxk4dXg3kbAw@mail.gmail.com>
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.30
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Jon Turney via Cygwin <cygwin@cygwin.com>
Reply-To: Jon Turney <jon.turney@dronecode.org.uk>
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="us-ascii"; Format="flowed"
Errors-To: cygwin-bounces~archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie.com@cygwin.com>

On 07/12/2024 05:26, Keith Thompson via Cygwin wrote:
> Brian Inglis wrote:
>> On 2024-12-06 19:16, Keith Thompson via Cygwin wrote:
>>> The use of "1$", "2$" et al in printf format specifiers is a
>>> POSIX-specific feature.
>>>
>>> On Cygwin (newlib) this is handled correctly in most cases, but one
>>> example I tried misbehaves.
>>> The output is correct on other implementations, including glibc and
>>> musl on Ubuntu.
>>>
>>> This C program:
>>>
>>> #include <stdio.h>
>>> int main(void) {
>>>       long long a = 123456789876543210;
>>>       double b=1.0/3;
>>>       printf("a:%2$8.8lld b:%1$10.2g\n", b, a);
>>> }
>>>
>>> should produce this output:
>>>
>>> a:123456789876543210 b:      0.33
>>>
>>> Under Cygwin (fully updated), with "gcc c.c -o c && ./c", the output is:
>>>
>>> a:140732550844138 b:  7.1e-315
>>>
>>
>> Confirmed with gcc 12.4 and minor tweaks to constant data types: printf is
>> ignoring arg positions:
> [SNIP]
> 
> It's not always ignoring arg positions. I think there's an interaction
> between the "1$" / "2$" position specification and relatively complex
> format specifiers.  The following case works correctly:
> 
> $ cat c2.c
> #include <stdio.h>
> int main(void) {
>      int a = 42;
>      double b = 1.0/3.0;
>      printf("a:%2$d b:%1$g\n", b, a);
>      printf("a:%1$d b:%2$g\n", a, b);
>      printf("a:%d b:%g\n",     a, b);
> }
> $ gcc c2.c -o c2 && ./c2
> a:42 b:0.333333
> a:42 b:0.333333
> a:42 b:0.333333
> $
> 
> (And the version of gcc shouldn't matter.  printf is implemented in
> newlib.  The code in question should be in newlib/libc/stdio/vfprintf.c.)

Not sure if this is the same/similar/different to the problem I reported 
at [1]

[1] https://sourceware.org/pipermail/newlib/2023/020374.html


-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
