php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23894 sprinf format Problem
Submitted: 2003-05-30 05:12 UTC Modified: 2003-05-30 08:51 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: s dot masugata at digicom dot dnp dot co dot jp Assigned:
Status: Closed Package: Strings related
PHP Version: 4.3.2 OS: RedHat Linux6.2J
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: s dot masugata at digicom dot dnp dot co dot jp
New email:
PHP Version: OS:

 

 [2003-05-30 05:12 UTC] s dot masugata at digicom dot dnp dot co dot jp
Operation of sprintf is amusing.
<?
$A = -1;
echo bin2hex( sprintf( "%02d:", $A ) );
phpinfo( );
?>

reslt:[2d31003a]

NULL is added.
It's satisfactory at 4.1.2 or 4.3.1.

An environmental problem?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-30 08:22 UTC] s dot masugata at digicom dot dnp dot co dot jp
printf does not operate, either.

<?
$A = -1;
printf( "%02d:", $A );
?>

reslt:[-1]

4.1.2 or 4.3.1:

reslt:[-1:]
 [2003-05-30 08:24 UTC] elmicha@php.net
No, it doesn't look like an environmental problem. sprintf() and printf() indeed append an extra NUL character for negative numbers:

% LC_ALL=C php -r '
printf( "%03d\n", -1 );
' | xxd
0000000: 2d30 3100 0a                             -01..

It happens also with "%02f" format.
 [2003-05-30 08:28 UTC] s dot masugata at digicom dot dnp dot co dot jp
Similarly, neither vsprintf nor vprintf also operates.

<?
$A = -1;

$Array[0] = $A;
echo bin2hex( vsprintf( "%02d:", $Array ) );

vprintf( "%02d:", $Array );
?>

reslt:[2d31003a]
reslt:[-1]

4.1.2 or 4.3.1:

reslt:[2d313a]
reslt:[-1:]
 [2003-05-30 08:39 UTC] s dot masugata at digicom dot dnp dot co dot jp
Thank you very much for Reply.

Since this function group is likely to be used quite extensively,
the influence range seems to be large.

A cause was not found although many things were investigated individually.

I'm sorry that reporting is only always possible.
 [2003-05-30 08:51 UTC] moriyoshi@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 22:01:28 2024 UTC