Bug #53297 [Opn->Csd]: gettimeofday implementation in php/win32/time.c can return 1mil usecs.
| From: | cataphract@php.net | Date: | Fri, 12 Nov 2010 18:38:24 +0000 |
| Subject: | Bug #53297 [Opn->Csd]: gettimeofday implementation in php/win32/time.c can return 1mil usecs. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-155973@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53297&edit=1
ID: 53297
Updated by: cataphract@php.net
Reported by: ped at 7gods dot org
Summary: gettimeofday implementation in php/win32/time.c can
return 1mil usecs.
-Status: Open
+Status: Closed
Type: Bug
Package: Unknown/Other Function
Operating System: Win32
PHP Version: 5.3.3
-Assigned To:
+Assigned To: cataphract
Block user comment: N
New Comment:
This bug has been fixed in SVN.
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/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2010-11-12 19:37:07] cataphract@php.net
Automatic comment from SVN on behalf of cataphract
Revision: http://svn.php.net/viewvc/?view=revision&revision=305298
Log: - Fixed bug #53297 (gettimeofday implementation in php/win32/time.c
can return
1 million microsecs). (ped at 7gods dot org)
- Moved line out of order in NEWS.
------------------------------------------------------------------------
[2010-11-12 11:31:15] ped at 7gods dot org
Description:
------------
in source file php/win32/time.c in function
PHPAPI int gettimeofday(struct timeval *time_Info, struct timezone
*timezone_Info)
toward end (L108 in 5.3.3 sources) there is this block of code:
if (time_Info->tv_usec > 1000000) {
time_Info->tv_usec -= 1000000;
++time_Info->tv_sec;
}
Doing >= would be more correct, like this:
if (time_Info->tv_usec >= 1000000) {
time_Info->tv_usec -= 1000000;
++time_Info->tv_sec;
}
(for most of the gettimeofday usage this is very minor bug, but while
profiling with xdebug extension on windows platform this does expose the
xdebug bug http://bugs.xdebug.org/view.php?id=357 which
together leads
to garbage profiling results)
Attached script does expose the problem also trough PHP (it fails at my
machine quite regularly, shouldn't take more then 2-3 runs to catch it).
Test script:
---------------
<?php
$safety_counter = 0;
do {
$t = gettimeofday();
} while( $t['usec'] < 1000000 && $safety_counter++ < 1000000 );
if ( $t['usec'] == 1000000 ) {
echo '<pre>', print_r( $t, TRUE ), '</pre>';
die('Returned gettimeofday array contains 1mil+ of microseconds (which
is 1second)!');
}
echo 'The gettimeofday didn\'t produce wrong value (tried it 1mil
times). Try again!';
?>
Expected result:
----------------
The returned $t['usec'] should never contain value >= 1000000, so the
script should always end with final echo.
Actual result:
--------------
$t['usec'] == 1000000 occasionally (on my machine at least once per 5
runs of script).
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53297&edit=1