| delorie.com/archives/browse.cgi | search |
| DMARC-Filter: | OpenDMARC Filter v1.4.2 delorie.com 4B9BmgPT796447 |
| 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 4B9BmgPT796447 |
| 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=vpGErSoR | |
| X-Recipient: | archive-cygwin AT delorie DOT com |
| DKIM-Filter: | OpenDKIM Filter v2.11.0 sourceware.org D00313858416 |
| DKIM-Signature: | v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; |
| s=default; t=1733744921; | |
| bh=SRWtsy9DycHTd0nj7DHLpWqvZ9CdYmvWdaQkNKIIgnU=; | |
| h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: | |
| List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: | |
| From; | |
| b=vpGErSoRHQEAHC1QiRFry6fPzw0BkHcJNaLZEntzrS6vDBswnxFASt3l936JVy2nf | |
| PSbo8BC1MnieyCQmwq5FIvaKKJrVDZJgEZheCJEms4oyd4dZ6PvxGAu4qO0OkTrilB | |
| XTX2DCrGVTuxiPTqNAdKHh2ztoqCsM2iE4aqDOIg= | |
| X-Original-To: | cygwin AT cygwin DOT com |
| Delivered-To: | cygwin AT cygwin DOT com |
| DKIM-Filter: | OpenDKIM Filter v2.11.0 sourceware.org DA0133858CDB |
| Date: | Mon, 9 Dec 2024 12:48:14 +0100 |
| To: | cygwin AT cygwin DOT com |
| Subject: | Re: Bug in handling of "1$", "2$" in printf format |
| Message-ID: | <Z1bY_pHnT4TTdKCb@calimero.vinschen.de> |
| Mail-Followup-To: | cygwin AT cygwin DOT com |
| References: | <CAAHpriPTSi-ji2xqX_yhNbtkdX_BxBr=tzchN=Gxk4dXg3kbAw AT mail DOT gmail DOT com> |
| <295c1185-c839-40df-80a7-2a59a4d742ca AT dronecode DOT org DOT uk> | |
| MIME-Version: | 1.0 |
| In-Reply-To: | <295c1185-c839-40df-80a7-2a59a4d742ca@dronecode.org.uk> |
| X-BeenThere: | cygwin AT cygwin DOT com |
| X-Mailman-Version: | 2.1.30 |
| List-Id: | General Cygwin discussions and problem reports <cygwin.cygwin.com> |
| List-Unsubscribe: | <https://cygwin.com/mailman/options/cygwin>, |
| <mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe> | |
| List-Archive: | <https://cygwin.com/pipermail/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-request AT cygwin DOT com?subject=help> |
| List-Subscribe: | <https://cygwin.com/mailman/listinfo/cygwin>, |
| <mailto:cygwin-request AT cygwin DOT com?subject=subscribe> | |
| From: | Corinna Vinschen via Cygwin <cygwin AT cygwin DOT com> |
| Reply-To: | cygwin AT cygwin DOT com |
| Cc: | Corinna Vinschen <corinna-cygwin AT cygwin DOT com> |
| Errors-To: | cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com |
| Sender: | "Cygwin" <cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com> |
On Dec 7 16:33, Jon Turney via Cygwin wrote:
> 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
Yeah, we might need a patch there...
Corinna
--
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
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |