public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
* Dangerous: localtime_r, gmtime_r
@ 2003-09-23 12:06 Brozinski, Stefan
  0 siblings, 0 replies; only message in thread
From: Brozinski, Stefan @ 2003-09-23 12:06 UTC (permalink / raw)
  To: 'pthreads-win32@sources.redhat.com'

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-09-23 12:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-23 12:06 Dangerous: localtime_r, gmtime_r Brozinski, Stefan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).