|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-10-07 12:45 UTC] timm dot forallthestuff at web dot de
Description: ------------ The error message displayed by php is irritating and not describing the problem correcly, when an argument in sprintf is incorrect (%$1s instead of %1$s). PHP Xampp installation, not really changed anything, so should be about the default. Reproduce code: --------------- $string = 'foo %$1s'; var_dump(sprintf($string, 'bar')); --- From manual page: function.sprintf#Parameter-Liste --- Expected result: ---------------- E_WARNING: error while parsing (or similiar) Actual result: -------------- Warning: sprintf() [function.sprintf]: Argument number must be greater than zero in PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 09:00:02 2025 UTC |
Here is a small patch for this. Index: ext/standard/formatted_print.c =================================================================== --- ext/standard/formatted_print.c (revision 289616) +++ ext/standard/formatted_print.c (working copy) @@ -449,9 +449,14 @@ if (format[temppos] == '$') { argnum = php_sprintf_getnumber(format, &inpos); - if (argnum <= 0) { + if ('%' == format[temppos-1]) { efree(result); efree(args); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Parse error, expecting argument specifier following '%' at string offset %d", temppos); + return NULL; + } else if (argnum <= 0) { + efree(result); + efree(args); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument number must be greater than zero"); return NULL; }c