Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:13073 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88200 invoked by uid 1010); 30 Sep 2004 09:32:43 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 88110 invoked from network); 30 Sep 2004 09:32:43 -0000 Received: from unknown (HELO web11.manitu.net) (217.11.48.111) by pb1.pair.com with SMTP; 30 Sep 2004 09:32:43 -0000 Received: from [62.165.4.166] (dicaprio.akademie1.de [62.165.4.166]) (authenticated) by web11.manitu.net (8.10.2-SOL3/8.10.2) with ESMTP id i8U9WaE13852 for ; Thu, 30 Sep 2004 11:32:36 +0200 To: internals@lists.php.net Content-Type: multipart/mixed; boundary="=-n9/gXfmQcVKjZGc6pcfT" Message-ID: <1096536756.2646.12.camel@dicaprio.akademie1.de> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Thu, 30 Sep 2004 11:32:36 +0200 Subject: Bug in *printf() (29733) From: twanger@bluetwanger.de (Markus Bertheau) --=-n9/gXfmQcVKjZGc6pcfT Content-Type: text/plain Content-Transfer-Encoding: 7bit Hi, I observed a long standing bug in the implementation of printf. When you want to reuse arguments using the %n$s syntax, printf wants one argument too many. Please review the attached patch and let me know if it can be commited. I created bug 29733 for this. http://bugs.php.net/bug.php?id=29733 If this is not the right mailing list, please let me know. -- Markus Bertheau --=-n9/gXfmQcVKjZGc6pcfT Content-Disposition: attachment; filename=formatted_print.c.patch Content-Type: text/x-patch; name=formatted_print.c.patch; charset=UTF-8 Content-Transfer-Encoding: 7bit --- ext/standard/formatted_print.c.orig 2004-07-18 19:28:04.000000000 +0200 +++ ext/standard/formatted_print.c 2004-08-27 14:23:07.580732341 +0200 @@ -537,12 +537,6 @@ php_sprintf_appendchar(&result, &outpos, &size, '%' TSRMLS_CC); inpos += 2; } else { - if (currarg >= argc && format[inpos + 1] != '%') { - efree(result); - efree(args); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too few arguments"); - return NULL; - } /* starting a new format specifier, reset variables */ alignment = ALIGN_RIGHT; adjusting = 0; @@ -574,13 +568,6 @@ argnum += format_offset; - if (argnum >= argc) { - efree(result); - efree(args); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too few arguments"); - return NULL; - } - /* after argnum comes modifiers */ PRINTF_DEBUG(("sprintf: looking for modifiers\n" "sprintf: now looking at '%c', inpos=%d\n", @@ -635,6 +622,13 @@ argnum = currarg++ + format_offset; } + if (argnum >= argc) { + efree(result); + efree(args); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too few arguments"); + return NULL; + } + if (format[inpos] == 'l') { inpos++; } --=-n9/gXfmQcVKjZGc6pcfT--