X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B70E9385C40A
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1637245928;
	bh=Hn6D38zgknJWRhXPfm7EwFcGGJQr4aiqXYjK8P+UVB4=;
	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=ajVqDWMRpfYWNOjM4xnIXTeCo0GVg8d2wc3CAZeoccSrYM7lQUwfbD2W7pHbdalQE
	 U9fpT52MzM7HDVxszewpQBKmOb4Rirb8x0Z9kKlsJoM+3ECJ8p0P6cu9zmq3F5cVwN
	 +r6OaOY1FsUkdEvJjoJzOkWRm3ubW67VNE+LPZ1U=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 10E63385800F
Date: Thu, 18 Nov 2021 15:27:42 +0100
To: cygwin@cygwin.com
Subject: Re: possible snprintf() regression in 3.3.2
Message-ID: <YZZi3rI5msk6ksAV@calimero.vinschen.de>
Mail-Followup-To: cygwin@cygwin.com
References: <20211117003718.GF10332@venus.tony.develop-help.com>
 <20211117182108.b38599f5e13071bf269a0d48@nifty.ne.jp>
 <YZT1S8wDnaBuYf5u@calimero.vinschen.de>
 <20211118000649.GG10332@venus.tony.develop-help.com>
 <20211118203538.a049809d57731fe375801c15@nifty.ne.jp>
 <YZZSzPhbqF6cQAiu@calimero.vinschen.de>
 <fa647f83-c5ed-6dea-fcba-c8b799abe12f@gmail.com>
MIME-Version: 1.0
Content-Disposition: inline
In-Reply-To: <fa647f83-c5ed-6dea-fcba-c8b799abe12f@gmail.com>
X-Provags-ID: V03:K1:AYS9E4bmgGXeNaBFy4q+hJoo80rCVeNmcw0KUI4fz6loJymVR0m
 wi8ch3Zjt+bR7awy95x+T0Ms11CVUkCliJF0WE2caO535I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VD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,
 SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.4
X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on
 server2.sourceware.org
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.29
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: Corinna Vinschen via Cygwin <cygwin@cygwin.com>
Reply-To: cygwin@cygwin.com
Cc: Corinna Vinschen <corinna-cygwin@cygwin.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cygwin-bounces+archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie.com@cygwin.com>

On Nov 18 16:11, Noel Grandin via Cygwin wrote:
> 
> 
> On 2021/11/18 3:19 pm, Corinna Vinschen via Cygwin wrote:
> > My patch raised NDEC from 43 to 1023 to allow aproximately the same
> > number of digits as glibc.  Newlib strives to support embedded targets
> > and bare metal.  Some of them are lucky if they have a stack size of 1K.
> > The outbuf buffer is created on the stack, so I used ndigits to save
> > stack space.
> > 
> > While that patch fixes the reported problem, it will make users of
> > smaller-than-Cygwin targets pretty unhappy.
> > 
> > A workaround would be to malloc outbuf instead.  Given that printf
> 
> printf is often performance sensitive, and using malloc there would likely be significantly slower.
> 
> Possibly use alloca() to allocate only the necessary amount on stack?

That's kind of what the current code does.

But that's apparently the problem.  The necessary amount is only known to
the current algorithm while populating outbuf already.  So before my
patch, outbuf had a constant size, but it was size restricted.

> Seems unlikely that embedded systems would be printing values that needed such large space anyway.

Perhaps that's a workaround:

Use a constant buffer size, but use NDEC = 1023 only on Cygwin for the
time being, something like NDEC = 64 otherwise...


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
