From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 9521 invoked from network); 16 Apr 2023 14:39:31 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 16 Apr 2023 14:39:31 -0000 Received: (qmail 25691 invoked by uid 550); 16 Apr 2023 14:39:28 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 25656 invoked from network); 16 Apr 2023 14:39:27 -0000 Date: Sun, 16 Apr 2023 10:39:14 -0400 From: Rich Felker To: Gabriel Ravier Cc: =?utf-8?B?SuKCkeKCmeKCmw==?= Gustedt , musl@lists.openwall.com Message-ID: <20230416143913.GN4163@brightrain.aerifal.cx> References: <20220908163649.634728-1-gabravier@gmail.com> <20230416085113.1c88ebe5@inria.fr> <30474c83-aa94-05d3-b7d6-aea3a0bd4e63@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <30474c83-aa94-05d3-b7d6-aea3a0bd4e63@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] [PATCH v2 1/1] vfprintf: support C2x %b and %B conversion specifiers On Sun, Apr 16, 2023 at 03:20:59PM +0200, Gabriel Ravier wrote: > On 4/16/23 08:51, Jā‚‘ā‚™ā‚› Gustedt wrote: > >Gabriel, > >it also seems to me that ... > > > >on Sat, 15 Apr 2023 14:28:28 +0200 you (Gabriel Ravier > >) wrote: > > > >>+ /* This buffer is used for integer conversions. As such, it needs > >>+ * to be able to contain the full representation of a number in base 2, > >>+ * 8, 10 or 16, with base 2 having the largest possible requirement of > >>+ * as many characters as the amount of bits in the largest > >>possible > >>+ * integer type */ > >>+ char buf[sizeof(uintmax_t)*CHAR_BIT]; > >... here a `+3` seems to be in order to take care of the `0[bx]` > >prefix and a terminating null byte. > > This buffer is only used specifically for storing converted digits, > and is never used to store the alternative form, and never contains > a null terminator either as the code knows the used length and never > passes the buffer to a function that doesn't do so, so from what I > can see these objections are wrong (in fact it wouldn't make much > sense to store the prefix in that buffer given that the code also > has to handle the possibility of extremely large 0-padding that goes > between the prefix and the converted digits). > > Though perhaps the comment could be improved, I suppose it could be > confusing... Yes, without looking I'm pretty sure you're right about what the buffer is and isn't used for. I think both the +3 and the +LDBL_MANT_DIG/4 are artifacts of proto-musl code long ago where things were done differently and floating point code was also in the main printf_core function and did naive floating point math. Maybe these should be fixed with a separate patch first (which I could make and explain what I recall of the history) so this unrelated change isn't a distraction from the %b patches. Rich