#30764 [Fbk->NoF]: printf + zero fill + negative number = extra null character on windows xp

From: Date: Fri, 28 Jan 2005 00:00:06 +0000
Subject: #30764 [Fbk->NoF]: printf + zero fill + negative number = extra null character on windows xp
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-72957@lists.php.net to get a copy of this message
 ID:               30764
 Updated by:       php-bugs@lists.php.net
 Reported By:      php at arantius dot com
-Status:           Feedback
+Status:           No Feedback
 Bug Type:         Output Control
 Operating System: Windows XP
 PHP Version:      4.3.9
 New Comment:

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".


Previous Comments:
------------------------------------------------------------------------

[2005-01-19 03:25:12] sniper@php.net

Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip


And try this script with the PHP CLI binary:

<?php
var_dump(sprintf("%0.2f", 1.51555));     
var_dump(sprintf("%0.2f", -1.51555));
var_dump(sprintf("%0.2f", -1));
var_dump(sprintf("%.2f", -1.5));
var_dump(sprintf("%.2f", -1.51555));
var_dump(sprintf("%0.2f", 1.51555));
?>



------------------------------------------------------------------------

[2004-11-11 21:06:19] php at arantius dot com

Description:
------------
When using printf, zero fill, floats, and negative numbers, PHP 4.3.9
on Windows XP Pro SP1 generates null characters at the end of the
number that should not be there.
Passing a negative number, i.e. -1, into the format string "%0.2f" will
give an invalid result, i.e. "-1.00[NULL]" where [NULL] is the 0th byte.

Reproduce code:
---------------
<?
printf("%0.2f<br />", 1.51555);     //ok
printf("%0.2f<br />", -1.51555);    //broken
printf("%0.2f<br />", -1);          //broken
printf("%.2f<br />", -1.5);         //ok
printf("%.2f<br />", -1.51555);     //ok
printf("%0.2f<br />", 1.51555);     //ok
?>

Expected result:
----------------
I expect "-1.00" or appropriately rounded values with no trailing null
bytes.

Actual result:
--------------
Cannot paste output, it is truncated at the first null byte.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=30764&edit=1


Thread (5 messages)

« previous php.bugs (#72957) next »