summaryrefslogtreecommitdiffstats
path: root/win/tclWinTime.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2003-05-24 02:30:47 (GMT)
committerdrh <drh@noemail.net>2003-05-24 02:30:47 (GMT)
commit9e61c4aaf05f742e7d17cdb9219bd0c16061631e (patch)
tree994821c7c9f5bc4f5d7a596b42e7f0176fb723db /win/tclWinTime.c
parentffbfca314cec66933154c7ef26603afb00cd0708 (diff)
downloadtcl-9e61c4aaf05f742e7d17cdb9219bd0c16061631e.zip
tcl-9e61c4aaf05f742e7d17cdb9219bd0c16061631e.tar.gz
tcl-9e61c4aaf05f742e7d17cdb9219bd0c16061631e.tar.bz2
Add tests to detect and avoid division by zero in the windows precision
timer calibration logic. FossilOrigin-Name: 7487febaec39ae0581dd636b05bdd42e7b197876
Diffstat (limited to 'win/tclWinTime.c')
-rw-r--r--win/tclWinTime.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/win/tclWinTime.c b/win/tclWinTime.c
index 9953085..593ca55 100644
--- a/win/tclWinTime.c
+++ b/win/tclWinTime.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclWinTime.c,v 1.18 2003/05/18 19:48:27 kennykb Exp $
+ * RCS: @(#) $Id: tclWinTime.c,v 1.19 2003/05/24 02:30:48 drh Exp $
*/
#include "tclWinInt.h"
@@ -348,7 +348,8 @@ Tcl_GetTime(timePtr)
TclpInitUnlock();
}
- if ( timeInfo.perfCounterAvailable ) {
+ if ( timeInfo.perfCounterAvailable
+ && timeInfo.curCounterFreq.QuadPart!=0 ) {
/*
* Query the performance counter and use it to calculate the
@@ -449,7 +450,6 @@ StopCalibration( ClientData unused )
*
* Results:
* Returns a pointer to a static string, or NULL on failure.
- * Return value is in UTF-8 encoding
*
* Side effects:
* None.
@@ -785,7 +785,7 @@ CalibrationThread( LPVOID arg )
/* Run the calibration once a second */
- for ( ; ; ) {
+ while (timeInfo.perfCounterAvailable) {
/* If the exitEvent is set, break out of the loop. */
@@ -856,6 +856,22 @@ UpdateTimeEachSecond()
EnterCriticalSection( &timeInfo.cs );
/*
+ * We devide by timeInfo.curCounterFreq.QuadPart in several places.
+ * That value should always be positive on a correctly functioning
+ * system. But it is good to be defensive about such matters.
+ * So if something goes wrong and the value does goes to zero, we
+ * clear the timeInfo.perfCounterAvailable in order to cause the
+ * calibration thread to shut itself down, then return without additional
+ * processing.
+ */
+
+ if( timeInfo.curCounterFreq.QuadPart==0 ){
+ LeaveCriticalSection( &timeInfo.cs );
+ timeInfo.perfCounterAvailable = 0;
+ return;
+ }
+
+ /*
* Several things may have gone wrong here that have to
* be checked for.
* (1) The performance counter may have jumped.