php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #49802 Irritating error message when passing irregular arguments for parsing (sprintf)
Submitted: 2009-10-07 12:45 UTC Modified: 2010-12-20 09:16 UTC
Votes:10
Avg. Score:3.0 ± 1.3
Reproduced:9 of 9 (100.0%)
Same Version:1 (11.1%)
Same OS:4 (44.4%)
From: timm dot forallthestuff at web dot de Assigned:
Status: Open Package: Strings related
PHP Version: 5.3.0 OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-13 16:54 UTC] chrisstocktonaz at gmail dot com
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
 [2010-12-20 09:16 UTC] jani@php.net
-Package: Feature/Change Request +Package: Strings related
 [2010-12-20 09:16 UTC] jani@php.net
-Operating System: Windows 7 +Operating System: *
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 08:01:29 2024 UTC