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 <[EMAIL PROTECTED]>
--- 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++;
 			}

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to