This is the mail archive of the pthreads-win32@sources.redhat.com mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Dangerous: localtime_r, gmtime_r


Hi all,

there is a problem with the current implementation of the thread safe
version of "localtime" and "gmtime" currently implemented as a macro in
<pthread.h>.

The current definition for localtime_r is:

#define localtime_r( _clock, _result ) \
	( *(_result) = *localtime( (_clock) ), \
	  (_result) )

The problem is that localtime() may return NULL. At least Microsoft's
implementation in MSVCRT[D].DLL does in fact return NULL if certain
conditions are met. Thus, a page fault may occur when using this
implementation.

I suggest to change the implementation from the current #define to a 'real'
function like:

struct tm *localtime_r(time_t *_clock, struct tm *_result)
{
  struct tm *p = localtime(_clock);

  if (p)
    *(_result) = *p;

  return p;
}

Regards
Stefan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]