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: 344526 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id CC927140119 for ; Fri, 2 May 2014 00:08:22 +1000 (EST) 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=krGD/PjjjkA6kMWCfSOMB2/9umCYE tJKhzQ7rPOEZxUEK4Fpn8zH2/m9r4Hr/fYwMkc0fXAl9uY43E/k2IM0KtbCTyZBu 2+6LSR2luJGAY0z/4VTFYaiLfhRjxDH9CVfncTsQNQ4OpgrkBHNnvVIxn5ZrjFFE HLs6+mMWYzkn7Q= 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=mzw GiwWyfC5IHC4M4c2sTtrkleXULvZ116v5XqPBrAi5qOLKDVqw/l1vVoCm+T0YmCV a3fxiHiSXswDuny8eswsVvhGsy8EQJ164Wqoy/VDYft534cwkoL262P/ZD/NCiqL mzpUTPT89kyMvxPwxC34Wk8E8ccPp/6a2+eUOA8U= 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 [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); \ } \ } \