Re: Bug #3443: sprintf pads a null-character with a negative float
| From: | thies at digicol dot de | Date: | Thu, 10 Feb 2000 09:34:25 +0000 |
| Subject: | Re: Bug #3443: sprintf pads a null-character with a negative float | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-15346@lists.php.net to get a copy of this message | ||
even shorter "proof":
<?
var_dump(sprintf("%0.6f",-122.440383));
var_dump("-122.440383");
?>
string(12) "-122.440383"
string(11) "-122.440383"
stig - any chance to look at it?
On Thu, Feb 10, 2000 at 12:35:06AM -0000, greg@bah.org wrote:
> 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
>
>
> --
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net
> For additional commands, e-mail: php-dev-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
--
Thies C. Arntzen "One Big-Mac, Small Fries and a Coke!"
Digital Collections Phone +49 40 235350 Fax +49 40 23535180
Hammerbrookstr. 93 20097 Hamburg / Germany