From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id E7BA43858400 for ; Wed, 10 Nov 2021 15:30:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E7BA43858400 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: /+ZJppbAKMBAIWeVICyVnNwG7piSHYignKdL0nuTy26O5ia0d77eL3AUur1sk9Pjyc13Elw4DS qoRGzAml6+GikkLaaF/dsDxvbf740fgwzE5LZuRcE94jvmRcmsnVTH9PUsPy1U8TLD/+9yig9j 0nmMqIrw7cceFljzXb7PGpKmh3vYI/ZeRmKsOS1InsOV7ubstnJTRI3fwSvsnG9gSSzZ6RDqzS BWsQPoPptallgQ5SZ0RupGWfDj6BECc03/rZdN2HwAqxvPh9slf3vxDSfA7wWx9veF6sjrF2W1 KGTFEn5JwVEKYg+C7oCYYJfe X-IronPort-AV: E=Sophos;i="5.87,224,1631606400"; d="scan'208";a="70778216" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 10 Nov 2021 07:30:13 -0800 IronPort-SDR: HQw7Gl02WpllCltQZ5x8IvHJNokm9i8/w5uJBo5MFjAcmwS498Q8cpOSvdv8Q2lgWUVlEg78T0 qAbJMlIBtAET5lCCU1LIm14Rs8e8ZBq7KKMXT8HniDV8Dvkl/AfhfwbmBj0OgCyfLA7RsuLYdU UAHBkz4r5TEpBDqyxFza3muYiItMwPts0BbVbymCMTBoG315Pttrp+hw7lfHMj2pCHUTQg5PvM nhFHh6er0iPvUOAvA0ooQUHNyzbDHWSt95Tif9MOMIjRVFW/q9wWCcQSYbIgg5bCM79MBnuSWp SE0= Date: Wed, 10 Nov 2021 15:30:08 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: Florian Weimer CC: Subject: Re: [PATCH v2] Support C2X printf %b, %B In-Reply-To: <87lf1w743t.fsf@oldenburg.str.redhat.com> Message-ID: References: <87lf1w743t.fsf@oldenburg.str.redhat.com> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-05.mgc.mentorg.com (139.181.222.5) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-3116.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Nov 2021 15:30:17 -0000 On Wed, 10 Nov 2021, Florian Weimer wrote: > * Joseph Myers: > > > +@item @samp{%b}, @samp{%B} > > +Print an integer as an unsigned binary number. @samp{%b} uses > > +lower-case @samp{b} with the @samp{#} flag and @samp{%B} uses > > +upper-case. @samp{%b} is an ISO C2X feature; @samp{%B} is an > > +extension recommended by ISO C2X. @xref{Integer Conversions}, for > > +details. > > The new tests do not contain any negative input numbers. Do they result > in undefined behavior? Negative input numbers result in undefined behavior when the specified argument type is unsigned after the integer promotions, as with %b with no length modifiers, since printf is specified to behave as if it uses va_arg (with the promoted version of the specified argument type), and mixing signed / unsigned types with va_arg is only valid when the value passed is representable in both types. Negative (int) input numbers are valid when the specified argument type is int (promoted from a narrower unsigned type), and the tests do include cases passing (int) 0x87654321 to %hb, %hB, %hhb, %hhB to test that. -- Joseph S. Myers joseph@codesourcery.com