From patchwork Sun Mar 1 20:52:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 444870 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 E246714017B for ; Mon, 2 Mar 2015 08:57:36 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=sourceware.org header.i=@sourceware.org header.b=pCCxSYV6; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:in-reply-to:references:from:date :subject:to; q=dns; s=default; b=h5+br2f9rxV1+7XUZaS1XQ903xCCRvv 3C6ccnDPLUnSILJ3sHr2eXLpos773oYRjCCf856DjZUcVs3Mz8WCEhynoKtYCsTr kA1hXs1tdn8IG9alDu62/6/2pw072NHXWinTv2y201svHCfcKgKT03h08PHGV3rH kGph81TiBBCo= 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:message-id:in-reply-to:references:from:date :subject:to; s=default; bh=9mXHakwqwUvbZKKjT55fjSMab24=; b=pCCxS YV68Dca8rXVioBcdfmtm51XCwvBF5ndhaQrY+O04zSS4S6jT7+MkFckNY5THgbE7 Wew7f4KGvNBpFcyj65Etuhpp0e3f/NPj2Dbr7h120KX2EpXDpMsXT8dfJCA/795b K8mM1mjpYtu6jdlQqLrFIVgzm9psSHUgbtESMI= Received: (qmail 104414 invoked by alias); 1 Mar 2015 21:57:30 -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 104398 invoked by uid 89); 1 Mar 2015 21:57:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.0 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Message-Id: In-Reply-To: References: From: Florian Weimer Date: Sun, 1 Mar 2015 21:52:15 +0100 Subject: [PATCH 3/6] vfprintf: Define WORK_BUFFER_SIZE To: libc-alpha@sourceware.org This constant will allow us to refer to the number of elements in work_buffer across a function call boundary. --- stdio-common/vfprintf.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/stdio-common/vfprintf.c b/stdio-common/vfprintf.c index 16e70b8..dcc24b3 100644 --- a/stdio-common/vfprintf.c +++ b/stdio-common/vfprintf.c @@ -235,7 +235,8 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap) const UCHAR_T *end_of_spec; /* Buffer intermediate results. */ - CHAR_T work_buffer[1000]; +#define WORK_BUFFER_SIZE 1000 + CHAR_T work_buffer[WORK_BUFFER_SIZE]; CHAR_T *workstart = NULL; CHAR_T *workend; @@ -986,7 +987,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap) /* Print description of error ERRNO. */ \ string = \ (CHAR_T *) __strerror_r (save_errno, (char *) work_buffer, \ - sizeof work_buffer); \ + WORK_BUFFER_SIZE * sizeof (CHAR_T)); \ is_long = 0; /* This is no wide-char string. */ \ goto LABEL (print_string) @@ -1366,7 +1367,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap) CHAR_T spec; workstart = NULL; - workend = &work_buffer[sizeof (work_buffer) / sizeof (CHAR_T)]; + workend = work_buffer + WORK_BUFFER_SIZE; /* Get current character in format string. */ JUMP (*++f, step0_jumps); @@ -1465,7 +1466,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap) goto all_done; } - if (width >= sizeof (work_buffer) / sizeof (work_buffer[0]) - 32) + if (width >= WORK_BUFFER_SIZE - 32) { /* We have to use a special buffer. The "32" is just a safe bet for all the output which is not counted in the width. */ @@ -1498,7 +1499,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap) goto all_done; } - if (width >= sizeof (work_buffer) / sizeof (work_buffer[0]) - 32) + if (width >= WORK_BUFFER_SIZE - 32) { /* We have to use a special buffer. The "32" is just a safe bet for all the output which is not counted in the width. */ @@ -1564,8 +1565,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap) } else prec = 0; - if (prec > width - && prec > sizeof (work_buffer) / sizeof (work_buffer[0]) - 32) + if (prec > width && prec > WORK_BUFFER_SIZE - 32) { if (__glibc_unlikely (prec >= INT_MAX / sizeof (CHAR_T) - 32)) { @@ -1935,7 +1935,7 @@ do_positional: CHAR_T spec = specs[nspecs_done].info.spec; workstart = NULL; - workend = &work_buffer[sizeof (work_buffer) / sizeof (CHAR_T)]; + workend = work_buffer + WORK_BUFFER_SIZE; /* Fill in last information. */ if (specs[nspecs_done].width_arg != -1) @@ -1969,8 +1969,7 @@ do_positional: } /* Maybe the buffer is too small. */ - if (MAX (prec, width) + 32 > (int) (sizeof (work_buffer) - / sizeof (CHAR_T))) + if (MAX (prec, width) + 32 > WORK_BUFFER_SIZE) { if (__libc_use_alloca ((MAX (prec, width) + 32) * sizeof (CHAR_T)))