From patchwork Thu Jan 19 11:50:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 63397 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 26978385841E for ; Thu, 19 Jan 2023 11:50:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26978385841E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674129043; bh=dt46SFE6G7t6GtDGLS6oyJvHBxXWn3gMARYarnH/hsM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ki5u9cxnhBXxeJ9kqCDiOLzz4sRj5clLgtYgcuGYoHlUkXcWQOXWlT+J1M8cU8oMF zUv6kvcdaHKKEmfLKFLJtzUDxMaUyRwIsxTXec3m10z7FbAX3BRR8vxlupd7rgtA94 aE0St+w/IY2qCm9wPv6voHlVLZ9p7g1Szzvtv4m0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id C7F953858C52 for ; Thu, 19 Jan 2023 11:50:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C7F953858C52 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id B54113768F for ; Thu, 19 Jan 2023 11:50:20 +0000 (UTC) Received: from hawking.suse.de (unknown [10.168.4.11]) by relay2.suse.de (Postfix) with ESMTP id AF2B02C141 for ; Thu, 19 Jan 2023 11:50:20 +0000 (UTC) Received: by hawking.suse.de (Postfix, from userid 17005) id 820C444029E; Thu, 19 Jan 2023 12:50:20 +0100 (CET) To: libc-alpha@sourceware.org Subject: [PATCH] Account for grouping in printf width (bug 23432) X-Yow: This PORCUPINE knows his ZIPCODE.. And he has ``VISA''!! Date: Thu, 19 Jan 2023 12:50:20 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Andreas Schwab via Libc-alpha From: Andreas Schwab Reply-To: Andreas Schwab Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This is a partial fix for mishandling of grouping when formatting integers. It properly computes the width in presence of grouping characteres when the precision is larger than the number of significant digits. --- stdio-common/Makefile | 1 + stdio-common/tst-grouping3.c | 37 +++++++++++++++++++++++++++++ stdio-common/vfprintf-process-arg.c | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 stdio-common/tst-grouping3.c diff --git a/stdio-common/Makefile b/stdio-common/Makefile index 6e9d104524..b46d932a20 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -195,6 +195,7 @@ tests := \ tst-gets \ tst-grouping \ tst-grouping2 \ + tst-grouping3 \ tst-long-dbl-fphex \ tst-memstream-string \ tst-obprintf \ diff --git a/stdio-common/tst-grouping3.c b/stdio-common/tst-grouping3.c new file mode 100644 index 0000000000..0031ad4010 --- /dev/null +++ b/stdio-common/tst-grouping3.c @@ -0,0 +1,37 @@ +/* Test printf with grouping and padding (bug 23432) + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +static int +do_test (void) +{ + char buf[80]; + + xsetlocale (LC_NUMERIC, "de_DE.UTF-8"); + + sprintf (buf, "%+-'13.9d", 1234567); + TEST_COMPARE_STRING (buf, "+001.234.567 "); + + return 0; +} + +#include diff --git a/stdio-common/vfprintf-process-arg.c b/stdio-common/vfprintf-process-arg.c index 2c651946df..cd3eaf5c0c 100644 --- a/stdio-common/vfprintf-process-arg.c +++ b/stdio-common/vfprintf-process-arg.c @@ -257,7 +257,7 @@ LABEL (unsigned_number): /* Unsigned number of base BASE. */ width -= 2; } - width -= workend - string + prec; + width -= number_length + prec; Xprintf_buffer_pad (buf, L_('0'), prec);