Bug #3443: sprintf pads a null-character with a negative float
| From: | greg at bah dot org | Date: | Thu, 10 Feb 2000 00:35:06 +0000 |
| Subject: | Bug #3443: sprintf pads a null-character with a negative float | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-15341@lists.php.net to get a copy of this message | ||
From: greg@bah.org
Operating system: RH Linux 6.1
PHP version: 3.0.14
PHP Bug Type: Misbehaving function
Bug description: sprintf pads a null-character with a negative float
This is a really strange problem, but sprintf seems to be padding a null character to the end of a
string when the string consists of a negative float. Here is a script that will reproduce the
problem:
<?
$string = -122.440383;
$new_string = sprintf("%0.6f", $string);
echo "string = $string<br>\n";
echo "new_string = $new_string<br>\n";
for ($j=0;$j<strlen($new_string);$j++) {
echo "letter #$j: " . ord($new_string[$j]) . "<br>\n";
}
?>
The output on php-3.0.14, php-3.0.13, php-4.0b3 looks like:
string = -122.440383
new_string = -122.440383
letter #0: 45
letter #1: 49
letter #2: 50
letter #3: 50
letter #4: 46
letter #5: 52
letter #6: 52
letter #7: 48
letter #8: 51
letter #9: 56
letter #10: 51
letter #11: 0
There is no null character at the end if the float is positive.
I noticed that php-3.0.12 doens't exhibit this behavior. The way I configured all these
different versions of php was:
Configure command: ./configure '--with-mhash' '--with-mcrypt'
'--disable-display-source' '--enable-debugger' '--enable-track-vars'
'--enable-debug' '--with-xml' '--with-oracle' '--without-gd'
'--with-apxs=../www/bin/apxs'
The one major difference I know between my versions of php-3.0.12 and the others is that 3.0.12
compiles against an older version of mcrypt and all these others compile against a newwr version.
This is probably irrelevant because I have no idea what mcrypt libraries would have to do with
sprintf, but I thought I'd mention it.
Thanks.
-Greg