From patchwork Thu May 1 14:08:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 774 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx22.g.dreamhost.com (mx2.sub5.homie.mail.dreamhost.com [208.113.200.128]) by wilcox.dreamhost.com (Postfix) with ESMTP id 32AE4360068 for ; Thu, 1 May 2014 07:08:20 -0700 (PDT) Received: by homiemail-mx22.g.dreamhost.com (Postfix, from userid 14307373) id B896B50F037C; Thu, 1 May 2014 07:08:19 -0700 (PDT) X-Original-To: glibc@patchwork.siddhesh.in Delivered-To: x14307373@homiemail-mx22.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx22.g.dreamhost.com (Postfix) with ESMTPS id 8A29750F0391 for ; Thu, 1 May 2014 07:08:19 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=SNUvh/itOi7cXVkqA0Mt3++mizN/m tBdgDqTj7BRraV79SrVSYkbA/VTdL27x/Rku+6GNf8QpczxzmmyJYLP1HGYwKb4Z U4LhGFZ9duZPIQhtpEgBfDNJWeVizcMS44ZDOa43ffbQjZpBLnwq2cYkGGYZB4Bs 9OZw3zJ8GtEbxw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; s=default; bh=RTFitlHP6N97hpi8qGbcX7ykUXM=; b=QqF nRPeP3eDNulUCg9479zfWDcxVoFxYJUVzP12u4wQhU/AD2uRrGgr1n8D14tluICV fknmT36XZ6XUdym+H8WoqTaRmJvGefnzY0Fkje6BFtF5+0U+J38DoFp62zZVfXnj F+hOKAqpjdTQhdgTjyyfKE409GpTDxt100BhAmsQ= Received: (qmail 3027 invoked by alias); 1 May 2014 14:08:17 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 3013 invoked by uid 89); 1 May 2014 14:08:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-HELO: mail-out.m-online.net X-Auth-Info: oFq35s06W0xK4HbzL1YRA4LJBq3gVEy/YgsaUaXd7fY= From: Andreas Schwab To: libc-alpha@sourceware.org Subject: [PATCH] Correctly handle %p in wprintf X-Yow: Hello... IRON CURTAIN? Send over a SAUSAGE PIZZA! World War III? No thanks! Date: Thu, 01 May 2014 16:08:10 +0200 Message-ID: <877g65wq0l.fsf@igel.home> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-DH-Original-To: glibc@patchwork.siddhesh.in [BZ #16890] * stdio-common/vfprintf.c (process_arg) [%p]: Mark string as wide when compiling wprintf. * stdio-common/tstdiomisc.c (t3): New function. (main): Call it. --- stdio-common/tstdiomisc.c | 19 +++++++++++++++++++ stdio-common/vfprintf.c | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/stdio-common/tstdiomisc.c b/stdio-common/tstdiomisc.c index 5a25ecc..2e0663a 100644 --- a/stdio-common/tstdiomisc.c +++ b/stdio-common/tstdiomisc.c @@ -46,6 +46,24 @@ t2 (void) return result; } +static int +t3 (void) +{ + char buf[80]; + wchar_t wbuf[80]; + int result = 0; + int retval; + + retval = sprintf (buf, "%p", (char *) NULL); + result |= retval != 5 || strcmp (buf, "(nil)") != 0; + + retval = swprintf (wbuf, sizeof (wbuf) / sizeof (wbuf[0]), + L"%p", (char *) NULL); + result |= retval != 5 || wcscmp (wbuf, L"(nil)") != 0; + + return result; +} + volatile double qnanval; volatile long double lqnanval; /* A sNaN is only guaranteed to be representable in variables with static (or @@ -243,6 +261,7 @@ main (int argc, char *argv[]) result |= t1 (); result |= t2 (); + result |= t3 (); result |= F (); result |= fflush (stdout) == EOF; diff --git a/stdio-common/vfprintf.c b/stdio-common/vfprintf.c index f7e5f61..c4ff833 100644 --- a/stdio-common/vfprintf.c +++ b/stdio-common/vfprintf.c @@ -936,7 +936,8 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap) /* Make sure the full string "(nil)" is printed. */ \ if (prec < 5) \ prec = 5; \ - is_long = 0; /* This is no wide-char string. */ \ + /* This is a wide string iff compiling wprintf. */ \ + is_long = sizeof (CHAR_T) > 1; \ goto LABEL (print_string); \ } \ } \