php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #60755
Patch formatted_print revision 2012-01-14 18:35 UTC by dohardgopro at gmail dot com

Patch formatted_print for SPL related Bug #60755

Patch version 2012-01-14 18:35 UTC

Return to Bug #60755 | Download this patch
Patch Revisions:

Developer: dohardgopro@gmail.com

diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c
index 4aebbf3..68093b7 100644
--- a/ext/standard/formatted_print.c
+++ b/ext/standard/formatted_print.c
@@ -354,6 +354,7 @@ php_sprintf_getnumber(char *buffer, int *pos)
  *   n    field size
  *  "."n  precision (floats only)
  *  "+"   Always place a sign (+ or -) in front of a number
+ *  "*"   The width is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted
  *
  * Type specifiers:
  *
@@ -504,7 +505,34 @@ php_formatted_print(int ht, int *len, int use_array, int format_offset TSRMLS_DC
 				if (format[inpos] == '.') {
 					inpos++;
 					PRINTF_DEBUG(("sprintf: getting precision\n"));
-					if (isdigit((int)format[inpos])) {
+
+					/* "*" modifier */
+					if (format[inpos] == '*') {
+						inpos++;
+
+						/* now we expect to find a precision arg */
+						if (multiuse) {
+							MAKE_STD_ZVAL(tmp);
+							*tmp = **(args[argnum]);
+							INIT_PZVAL(tmp);
+							zval_copy_ctor(tmp);
+						} else {
+							SEPARATE_ZVAL(args[argnum]);
+							tmp = *(args[argnum]);
+						}
+						convert_to_long(tmp);
+
+						if (Z_LVAL_P(tmp) > 0 && Z_LVAL_P(tmp) < INT_MAX) {
+							precision = Z_LVAL_P(tmp);
+							adjusting |= ADJ_PRECISION;
+							expprec = 1;
+						} else {
+							efree(result);
+							efree(args);
+							php_error_docref(NULL TSRMLS_CC, E_WARNING, "Precision must be greater than zero and less than %d", INT_MAX);
+							return NULL;
+						}
+					} else if (isdigit((int)format[inpos])) {
 						if ((precision = php_sprintf_getnumber(format, &inpos)) < 0) {
 							efree(result);
 							efree(args);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 10:01:26 2024 UTC