#24872 [Opn->Csd]: sprintf() returns trailing NULL character
| From: | sniper@php.net | Date: | Wed, 30 Jul 2003 16:40:14 +0000 |
| Subject: | #24872 [Opn->Csd]: sprintf() returns trailing NULL character | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-45068@lists.php.net to get a copy of this message | ||
ID: 24872
Updated by: sniper@php.net
Reported By: kostas at nasis dot com
-Status: Open
+Status: Closed
Bug Type: Feature/Change Request
Operating System: Redhat 7.3, 8
PHP Version: 4.3.2
New Comment:
Seems to be fixed in CVS since I get the expected result.
Previous Comments:
------------------------------------------------------------------------
[2003-07-30 09:56:15] kostas at nasis dot com
Description:
------------
sprintf() will return a trailing NULL character under certain
conditions. See code below.
Reproduce code:
---------------
<?php
$blah = sprintf("%04d", -500);
echo "$blah\n";
// display ASCII code for each character of $blah
for ($i = 0; $i < strlen($blah); $i++) {
echo ord($blah{$i}) . "\n";
}
?>
Expected result:
----------------
The code should output:
-500
45
53
48
48
Actual result:
--------------
On PHP v4.3.2 it outputs:
-500
45
53
48
48
0
Notice the NULL (0) character at the end.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=24872&edit=1