diff options
author | Kevin B Kenny <kennykb@acm.org> | 2005-07-15 22:32:10 (GMT) |
---|---|---|
committer | Kevin B Kenny <kennykb@acm.org> | 2005-07-15 22:32:10 (GMT) |
commit | 17e8b8c78b5e27af69840be8b58596569f0f76e9 (patch) | |
tree | f4f327c96f30c6ee6facef575583b231fed32517 /generic/tclClock.c | |
parent | d70bdad3a4f08813f469ec8657f35f9096d3f454 (diff) | |
download | tcl-17e8b8c78b5e27af69840be8b58596569f0f76e9.zip tcl-17e8b8c78b5e27af69840be8b58596569f0f76e9.tar.gz tcl-17e8b8c78b5e27af69840be8b58596569f0f76e9.tar.bz2 |
Bug 1237907
Diffstat (limited to 'generic/tclClock.c')
-rw-r--r-- | generic/tclClock.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/generic/tclClock.c b/generic/tclClock.c index 6611576..9f3816b 100644 --- a/generic/tclClock.c +++ b/generic/tclClock.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclClock.c,v 1.37 2004/10/30 18:04:00 kennykb Exp $ + * RCS: @(#) $Id: tclClock.c,v 1.38 2005/07/15 22:32:23 kennykb Exp $ */ #include "tclInt.h" @@ -166,6 +166,14 @@ TclClockLocaltimeObjCmd( ClientData clientData, } TzsetIfNecessary(); timeVal = ThreadSafeLocalTime( &tock ); + if ( timeVal == NULL ) { + Tcl_SetObjResult(interp, + Tcl_NewStringObj("localtime failed (clock " + "value may be too large/" + "small to represent)", -1)); + Tcl_SetErrorCode(interp, "CLOCK", "localtimeFailed", (char*) NULL); + return TCL_ERROR; + } /* Package the results */ @@ -210,12 +218,19 @@ ThreadSafeLocalTime(timePtr) struct tm *tmPtr = (struct tm *) Tcl_GetThreadData(&tmKey, (int) sizeof(struct tm)); + struct tm *sysTmPtr; #ifdef HAVE_LOCALTIME_R localtime_r(timePtr, tmPtr); #else Tcl_MutexLock(&clockMutex); - memcpy((VOID *) tmPtr, (VOID *) localtime(timePtr), sizeof(struct tm)); - Tcl_MutexUnlock(&clockMutex); + sysTmPtr = localtime(timePtr); + if ( sysTmPtr == NULL ) { + Tcl_MutexUnlock( &clockMutex ); + return NULL; + } else { + memcpy((VOID *) tmPtr, (VOID *) localtime(timePtr), sizeof(struct tm)); + Tcl_MutexUnlock(&clockMutex); + } #endif return tmPtr; } |