From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13258 invoked by alias); 23 Sep 2003 12:06:49 -0000 Mailing-List: contact pthreads-win32-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sources.redhat.com Received: (qmail 13225 invoked from network); 23 Sep 2003 12:06:47 -0000 Received: from unknown (HELO relay.materna.de) (193.96.115.65) by sources.redhat.com with SMTP; 23 Sep 2003 12:06:47 -0000 Received: from ganymed.materna.de (ganymed [139.2.34.141]) by relay.materna.de (Postfix) with ESMTP id 4D41F67F3 for ; Tue, 23 Sep 2003 14:06:43 +0200 (MEST) Received: from ganymed.materna.de (localhost [127.0.0.1]) by mail.materna.de (Postfix) with ESMTP id 12420D901 for ; Tue, 23 Sep 2003 14:06:46 +0200 (MET DST) Received: from hb-castor.hb.buc.materna.com (hb-castor.hb.materna.de [139.2.228.234]) by mail.materna.de (Postfix) with ESMTP id E3805D900 for ; Tue, 23 Sep 2003 14:06:45 +0200 (MET DST) Received: by hb-castor.hb.buc.materna.com with Internet Mail Service (5.5.2653.19) id ; Tue, 23 Sep 2003 14:06:45 +0200 Message-ID: <5BD61062E524E244ADD87F7988480EC3C82369@hb-castor.hb.buc.materna.com> From: "Brozinski, Stefan" To: "'pthreads-win32@sources.redhat.com'" Subject: Dangerous: localtime_r, gmtime_r Date: Tue, 23 Sep 2003 12:06:00 -0000 MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2003/txt/msg00092.txt.bz2 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 . 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