From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7436 invoked by alias); 22 Jan 2007 16:06:11 -0000 Received: (qmail 7412 invoked by uid 22791); 22 Jan 2007 16:06:10 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 22 Jan 2007 16:06:03 +0000 Received: from sunsite.mff.cuni.cz (localhost.localdomain [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.8/8.13.8) with ESMTP id l0MG9n3t017180; Mon, 22 Jan 2007 17:09:49 +0100 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.13.8/8.13.8/Submit) id l0MG9mZK017179; Mon, 22 Jan 2007 17:09:48 +0100 Date: Mon, 22 Jan 2007 16:06:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Fix _itoa (0LL, ...) for bases other than 8 and 16 [BZ #3902] Message-ID: <20070122160948.GL3819@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2007-01/txt/msg00008.txt.bz2 Hi! While _itoa_word for 0L as first argument always adds 0 into the buffer for all bases (all the loops are do ... while (value != 0);) and so does the RUN_2N macro in _itoa as well (i.e. _itoa (0LL, bufend, 8, 0) or _itoa (0LL, bufend, 16, 0) both return "0"), _itoa (0LL, bufend, x, 0) for x != 8 && x != 16 returns "". stdio-common/vfprintf.c IMHO correctly relies on the 0 being added, as shown on the following testcase. Fixed by making sure 0 is added for value == 0 for all bases. 2007-01-22 Jakub Jelinek [BZ #3902] * stdio-common/_itoa.c (_itoa): If value is 0, always add 0 into the buffer. * stdio-common/tst-sprintf.c (main): Add test for %0lld with 0LL. --- libc/stdio-common/_itoa.c.jj 2004-06-06 08:02:14.000000000 +0200 +++ libc/stdio-common/_itoa.c 2007-01-22 16:46:39.000000000 +0100 @@ -1,5 +1,5 @@ /* Internal function for converting integers to ASCII. - Copyright (C) 1994, 1995, 1996, 1999, 2000, 2002, 2003, 2004 + Copyright (C) 1994, 1995, 1996, 1999, 2000, 2002, 2003, 2004, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Torbjorn Granlund @@ -272,7 +272,7 @@ _itoa (value, buflim, base, upper_case) #if BITS_PER_MP_LIMB == 64 mp_limb_t base_multiplier = brec->base_multiplier; if (brec->flag) - while (value != 0) + do { mp_limb_t quo, rem, x, dummy; @@ -282,8 +282,9 @@ _itoa (value, buflim, base, upper_case) *--buflim = digits[rem]; value = quo; } + while (value != 0); else - while (value != 0) + do { mp_limb_t quo, rem, x, dummy; @@ -293,6 +294,7 @@ _itoa (value, buflim, base, upper_case) *--buflim = digits[rem]; value = quo; } + while (value != 0); #endif #if BITS_PER_MP_LIMB == 32 mp_limb_t t[3]; @@ -394,6 +396,11 @@ _itoa (value, buflim, base, upper_case) n = 2; } } + else if (value == 0) + { + *--buflim = '0'; + return buflim; + } else { t[0] = value; --- libc/stdio-common/tst-sprintf.c.jj 2003-06-25 13:04:49.000000000 +0200 +++ libc/stdio-common/tst-sprintf.c 2007-01-22 16:51:33.000000000 +0100 @@ -37,5 +37,13 @@ main (void) free (dst); } + if (sprintf (buf, "%0d %0ld %0lld", 0, 0L, 0LL) != 5 + || strcmp (buf, "0 0 0") != 0) + { + printf ("sprintf (buf, \"%%0d %%0ld %%0lld\", 0, 0L, 0LL) produced \"%s\"\n", + buf); + result = 1; + } + return result; } Jakub