#29733 [Opn]: printf handles repeated placeholders wrong

2004-08-27 Thread bugs dot php dot net at bluetwanger dot de
 ID:  29733
 User updated by: bugs dot php dot net at bluetwanger dot de
 Reported By: bugs dot php dot net at bluetwanger dot de
 Status:  Open
-Bug Type:Unknown/Other Function
+Bug Type:Strings related
 PHP Version: 5.0.1
 New Comment:

Here's a patch:

--- ext/standard/formatted_print.c.orig 2004-07-18 19:28:04.0
+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++;
}

Let's see if the line breaks survive.

It basically removes the bogus (format[inpos + 1] != '%' will always be
true there) arg number check and moves the right one outside the special
case for complicated format specifiers.


Previous Comments:


[2004-08-18 14:46:41] bugs dot php dot net at bluetwanger dot de

Description:

printf('%s - %s %s %3$s %2$s', 1, 2, 3);

complains:

Warning: printf(): Too few arguments in /home/bertheau/printf.php on
line 2

printf('%s - %s %s %3$s %2$s', 1, 2, 3, 4);

does not complain and prints:

1 - 2 3 3 2

I expect the first version to not complain and print what the second
version prints.







-- 
Edit this bug report at http://bugs.php.net/?id=29733edit=1


#29733 [Opn]: printf handles repeated placeholders wrong

2004-08-27 Thread bugs dot php dot net at bluetwanger dot de
 ID:  29733
 User updated by: bugs dot php dot net at bluetwanger dot de
 Reported By: bugs dot php dot net at bluetwanger dot de
 Status:  Open
 Bug Type:Strings related
 PHP Version: 5.0.1
 New Comment:

Here's a link:
http://www.bluetwanger.de/~mbertheau/formatted_print.c.patch

You make it really hard to submit a patch. This bug thing has no
provision for attaching a file and you have to strain a lot to get at
an email address of a developer mailing list.


Previous Comments:


[2004-08-27 14:30:33] bugs dot php dot net at bluetwanger dot de

Here's a patch:

--- ext/standard/formatted_print.c.orig 2004-07-18 19:28:04.0
+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++;
}

Let's see if the line breaks survive.

It basically removes the bogus (format[inpos + 1] != '%' will always be
true there) arg number check and moves the right one outside the special
case for complicated format specifiers.



[2004-08-18 14:46:41] bugs dot php dot net at bluetwanger dot de

Description:

printf('%s - %s %s %3$s %2$s', 1, 2, 3);

complains:

Warning: printf(): Too few arguments in /home/bertheau/printf.php on
line 2

printf('%s - %s %s %3$s %2$s', 1, 2, 3, 4);

does not complain and prints:

1 - 2 3 3 2

I expect the first version to not complain and print what the second
version prints.







-- 
Edit this bug report at http://bugs.php.net/?id=29733edit=1