From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.133]) by sourceware.org (Postfix) with ESMTPS id 10E63385800F for ; Thu, 18 Nov 2021 14:27:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 10E63385800F Received: from calimero.vinschen.de ([24.134.7.25]) by mrelayeu.kundenserver.de (mreue010 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MLzWL-1n5WM227c1-00Hx4R for ; Thu, 18 Nov 2021 15:27:43 +0100 Received: by calimero.vinschen.de (Postfix, from userid 500) id C6979A80D32; Thu, 18 Nov 2021 15:27:42 +0100 (CET) Date: Thu, 18 Nov 2021 15:27:42 +0100 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: possible snprintf() regression in 3.3.2 Message-ID: Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: <20211117003718.GF10332@venus.tony.develop-help.com> <20211117182108.b38599f5e13071bf269a0d48@nifty.ne.jp> <20211118000649.GG10332@venus.tony.develop-help.com> <20211118203538.a049809d57731fe375801c15@nifty.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Provags-ID: V03:K1:AYS9E4bmgGXeNaBFy4q+hJoo80rCVeNmcw0KUI4fz6loJymVR0m wi8ch3Zjt+bR7awy95x+T0Ms11CVUkCliJF0WE2caO535IEbh5hzfdYjRwBu1dKwZQjYgLE KVUhrGIHQnc7ZtXaukO9JnN6l+C32NI+W+0mIkSWcvu03tHqdXHw47/5CqbIuXkoGSeU2dx 8YFrrNMLI+0d3VJ1i7Alg== X-UI-Out-Filterresults: notjunk:1;V03:K0:5U9ilh+mx3M=:RF7mqAELqnQadxxbOJPnw/ gJCVQjhk9BFehfBI8H4noSoQnQhYqdaq6Sbn3UPLFsxVK2MG5CM997shMD21QxM76ZTrpjCFa TcDLOUf3Mn+nrGA9O5GH/A9HjR3pZLuwlHEhXmpaV1TCgPCfhsfR4f+tzIlPNfAblwGm6/5ap TfizpOirsD4F/zJ89cp2IvEc3GPEXx6Ex3CpieNhAEqZ1O3fCzaEfG5wINkdF+eNkiM8F3kBk OZEQI1IAw0WxIPxOD4CQ5FoU/4E4eM8KWYcfnAgY3lBX2d3jPsOeYS997hakf/0PZz2dgkDZJ oYS/sHtc2YWMh7shmORKnc9oWeJMktaCXj3eYMcVh9n/tp5CS1PgSZUxX99Hfgfaf9ZCzIb6v RsgcdQD0UMq0Mmx0atPFUUJo2KJGUiKFCU20DLCCQjLaEBj3dsx3unKzqmVbhBmI3CjAXyjh4 V3gSqt7qkpedDbZ9Fw4oGfrMqEKP4f4XtEG9MZ3eYfpN8jqoshaemrT2QbBzQeBnIrygkLHUE ywp/0qv8Hk35MHh3p1+k4ljilBp6Nh6+38xkRneucyWflAYC4yboHh+tWSJsDQdcTORYrAIEd M657Zoom8/1SpjlHF2D5cZ3HFcwhLlSKFlLANMKDpeaxkzdGPsYGeenFpOhyvbfy//jPKHeU5 6W4SflFMApwpuL20OdknLwZGQ6Jjil+MdprXfIfioUOyA9qslsXLzeNqKEMRXQhbfH9f77Ky+ eyPuPaEu/lCdHWTo X-Spam-Status: No, score=-99.1 required=5.0 tests=BAYES_00, GOOD_FROM_CORINNA_CYGWIN, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_NUMSUBJECT, RCVD_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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Nov 2021 14:27:47 -0000 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