]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Correct the logic from f14754fbd for tor_gmtime_r
authorJohn Brooks <special@dereferenced.net>
Tue, 4 Jan 2011 04:36:09 +0000 (21:36 -0700)
committerNick Mathewson <nickm@torproject.org>
Thu, 28 Apr 2011 21:13:45 +0000 (17:13 -0400)
src/common/compat.c

index 9b7c0b7822d7b8853e1f4a312c8f3210ca0504b0..3644bd99962cf497611ee692dfae6206525cc85f 100644 (file)
@@ -2112,7 +2112,7 @@ tor_localtime_r(const time_t *timep, struct tm *result)
  * Convert *<b>timep</b> to a struct tm in UTC, and store the value in
  * *<b>result</b>.  Return the result on success, or NULL on failure.
  */
-#ifndef HAVE_GMTIME_R
+#ifdef HAVE_GMTIME_R
 struct tm *
 tor_gmtime_r(const time_t *timep, struct tm *result)
 {
@@ -2130,7 +2130,8 @@ tor_gmtime_r(const time_t *timep, struct tm *result)
   tor_assert(result);
   tor_mutex_acquire(m);
   r = gmtime(timep);
-  memcpy(result, r, sizeof(struct tm));
+  if (r)
+    memcpy(result, r, sizeof(struct tm));
   tor_mutex_release(m);
   return correct_tm(0, timep, result, r);
 }
@@ -2141,7 +2142,8 @@ tor_gmtime_r(const time_t *timep, struct tm *result)
   struct tm *r;
   tor_assert(result);
   r = gmtime(timep);
-  memcpy(result, r, sizeof(struct tm));
+  if (r)
+    memcpy(result, r, sizeof(struct tm));
   return correct_tm(0, timep, result, r);
 }
 #endif