php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53297 gettimeofday implementation in php/win32/time.c can return 1mil usecs.
Submitted: 2010-11-12 11:31 UTC Modified: 2010-11-12 19:37 UTC
From: ped at 7gods dot org Assigned: cataphract (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: 5.3.3 OS: Win32
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ped at 7gods dot org
New email:
PHP Version: OS:

 

 [2010-11-12 11:31 UTC] 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).

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-12 19:37 UTC] cataphract@php.net
Automatic comment from SVN on behalf of cataphract
Revision: http://svn.php.net/viewvc/?view=revision&amp;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 19:38 UTC] cataphract@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cataphract
 [2010-11-12 19:38 UTC] cataphract@php.net
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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 15:01:30 2024 UTC