emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r116113: Fix miscellaneous update-game-score bugs.


From: Paul Eggert
Subject: [Emacs-diffs] trunk r116113: Fix miscellaneous update-game-score bugs.
Date: Wed, 22 Jan 2014 19:02:45 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 116113
revision-id: address@hidden
parent: address@hidden
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Wed 2014-01-22 11:02:41 -0800
message:
  Fix miscellaneous update-game-score bugs.
  
  * configure.ac (difftime): Remove.
  * lib/update-game-score.c (difftime) [!HAVE_DIFFTIME]: Remove.
  (read_score) [HAVE_GETDELIM]: Don't access uninitialized storage.
  (read_scores, write_scores): Check for fclose failure.
  (write_scores): Use fchmod, not chmod, to avoid a race.
  (lock_file): Fix test for out-of-date lock file; it was reversed.
  Use ordinary subtraction rather than difftime; since we're already
  assuming POSIX we don't need to worry about the possibility of
  time_t being a magic cookie.
modified:
  ChangeLog                      changelog-20091113204419-o5vbwnq5f7feedwu-1538
  configure.ac                   
configure.in-20091113204419-o5vbwnq5f7feedwu-783
  lib-src/ChangeLog              changelog-20091113204419-o5vbwnq5f7feedwu-1608
  lib-src/update-game-score.c    
updategamescore.c-20091113204419-o5vbwnq5f7feedwu-2389
=== modified file 'ChangeLog'
--- a/ChangeLog 2014-01-22 01:43:37 +0000
+++ b/ChangeLog 2014-01-22 19:02:41 +0000
@@ -1,3 +1,8 @@
+2014-01-22  Paul Eggert  <address@hidden>
+
+       Fix miscellaneous update-game-score bugs.
+       * configure.ac (difftime): Remove.
+
 2014-01-20  Paul Eggert  <address@hidden>
 
        Merge from gnulib, incorporating:

=== modified file 'configure.ac'
--- a/configure.ac      2014-01-11 13:36:06 +0000
+++ b/configure.ac      2014-01-22 19:02:41 +0000
@@ -3468,7 +3468,6 @@
 strsignal setitimer \
 sendto recvfrom getsockname getpeername getifaddrs freeifaddrs \
 gai_strerror getline getdelim sync \
-difftime \
 getpwent endpwent getgrent endgrent \
 touchlock \
 cfmakeraw cfsetspeed copysign __executable_start log2)

=== modified file 'lib-src/ChangeLog'
--- a/lib-src/ChangeLog 2014-01-22 02:44:44 +0000
+++ b/lib-src/ChangeLog 2014-01-22 19:02:41 +0000
@@ -1,3 +1,15 @@
+2014-01-22  Paul Eggert  <address@hidden>
+
+       Fix miscellaneous update-game-score bugs.
+       * update-game-score.c (difftime) [!HAVE_DIFFTIME]: Remove.
+       (read_score) [HAVE_GETDELIM]: Don't access uninitialized storage.
+       (read_scores, write_scores): Check for fclose failure.
+       (write_scores): Use fchmod, not chmod, to avoid a race.
+       (lock_file): Fix test for out-of-date lock file; it was reversed.
+       Use ordinary subtraction rather than difftime; since we're already
+       assuming POSIX we don't need to worry about the possibility of
+       time_t being a magic cookie.
+
 2014-01-19  Paul Eggert  <address@hidden>
 
        update-game-score fixes for -m and integer overflow (Bug#16428)

=== modified file 'lib-src/update-game-score.c'
--- a/lib-src/update-game-score.c       2014-01-19 08:50:53 +0000
+++ b/lib-src/update-game-score.c       2014-01-22 19:02:41 +0000
@@ -59,11 +59,6 @@
 #define MAX_ATTEMPTS 5
 #define MAX_DATA_LEN 1024
 
-#ifndef HAVE_DIFFTIME
-/* OK on POSIX (time_t is arithmetic type) modulo overflow in subtraction.  */
-#define difftime(t1, t0) (double)((t1) - (t0))
-#endif
-
 static _Noreturn void
 usage (int err)
 {
@@ -275,6 +270,7 @@
 #ifdef HAVE_GETDELIM
   {
     size_t count = 0;
+    score->username = 0;
     if (getdelim (&score->username, &count, ' ', f) < 1
        || score->username == NULL)
       return -1;
@@ -371,14 +367,13 @@
   while ((readval = read_score (f, &entry)) == 0)
     if (push_score (&ret, &scorecount, &cursize, &entry) < 0)
       return -1;
-  if (readval > 0)
+  if (readval > 0 && fclose (f) == 0)
     {
       *count = scorecount;
       *alloc = cursize;
       *scores = ret;
       retval = 0;
     }
-  fclose (f);
   return retval;
 }
 
@@ -448,6 +443,8 @@
   fd = mkostemp (tempfile, 0);
   if (fd < 0)
     return -1;
+  if (fchmod (fd, 0644) != 0)
+    return -1;
   f = fdopen (fd, "w");
   if (! f)
     return -1;
@@ -456,10 +453,9 @@
                 scores[i].score, scores[i].username, scores[i].data)
        < 0)
       return -1;
-  fclose (f);
-  if (rename (tempfile, filename) < 0)
+  if (fclose (f) != 0)
     return -1;
-  if (chmod (filename, 0644) < 0)
+  if (rename (tempfile, filename) != 0)
     return -1;
   return 0;
 }
@@ -479,9 +475,9 @@
   *state = lockpath;
  trylock:
   attempts++;
-  /* If the lock is over an hour old, delete it. */
+  /* If the lock is over an hour old, delete it.  */
   if (stat (lockpath, &buf) == 0
-      && (difftime (buf.st_ctime, time (NULL) > 60*60)))
+      && 60 * 60 < time (0) - buf.st_ctime)
     unlink (lockpath);
   fd = open (lockpath, O_CREAT | O_EXCL, 0600);
   if (fd < 0)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]