[tor-commits] [tor/master] add LCOV_EXCL for unreachable exit() blocks in src/common

nickm at torproject.org nickm at torproject.org
Thu Jun 16 13:50:57 UTC 2016


commit d1ab295d7b2c4c8bd3da5e1774bc352f8cfe72ab
Author: Nick Mathewson <nickm at torproject.org>
Date:   Thu Jun 16 09:50:52 2016 -0400

    add LCOV_EXCL for unreachable exit() blocks in src/common
---
 src/common/aes.c             |  2 ++
 src/common/compat.c          |  4 ++++
 src/common/compat_libevent.c |  2 ++
 src/common/util.c            | 16 +++++++++++++++-
 4 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/common/aes.c b/src/common/aes.c
index db250c8..2b8a68c 100644
--- a/src/common/aes.c
+++ b/src/common/aes.c
@@ -238,9 +238,11 @@ evaluate_ctr_for_aes(void)
 
   if (fast_memneq(output, encrypt_zero, 16)) {
     /* Counter mode is buggy */
+    /* LCOV_EXCL_START */
     log_err(LD_CRYPTO, "This OpenSSL has a buggy version of counter mode; "
                   "quitting tor.");
     exit(1);
+    /* LCOV_EXCL_STOP */
   }
   return 0;
 }
diff --git a/src/common/compat.c b/src/common/compat.c
index 023325b..370881b 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -2876,18 +2876,22 @@ tor_gettimeofday(struct timeval *timeval)
   /* number of 100-nsec units since Jan 1, 1601 */
   GetSystemTimeAsFileTime(&ft.ft_ft);
   if (ft.ft_64 < EPOCH_BIAS) {
+    /* LCOV_EXCL_START */
     log_err(LD_GENERAL,"System time is before 1970; failing.");
     exit(1);
+    /* LCOV_EXCL_STOP */
   }
   ft.ft_64 -= EPOCH_BIAS;
   timeval->tv_sec = (unsigned) (ft.ft_64 / UNITS_PER_SEC);
   timeval->tv_usec = (unsigned) ((ft.ft_64 / UNITS_PER_USEC) % USEC_PER_SEC);
 #elif defined(HAVE_GETTIMEOFDAY)
   if (gettimeofday(timeval, NULL)) {
+    /* LCOV_EXCL_START */
     log_err(LD_GENERAL,"gettimeofday failed.");
     /* If gettimeofday dies, we have either given a bad timezone (we didn't),
        or segfaulted.*/
     exit(1);
+    /* LCOV_EXCL_STOP */
   }
 #elif defined(HAVE_FTIME)
   struct timeb tb;
diff --git a/src/common/compat_libevent.c b/src/common/compat_libevent.c
index 96fcec5..4469f15 100644
--- a/src/common/compat_libevent.c
+++ b/src/common/compat_libevent.c
@@ -228,8 +228,10 @@ tor_libevent_initialize(tor_libevent_cfg *torcfg)
 #endif
 
   if (!the_event_base) {
+    /* LCOV_EXCL_START */
     log_err(LD_GENERAL, "Unable to initialize Libevent: cannot continue.");
     exit(1);
+    /* LCOV_EXCL_STOP */
   }
 
   /* Making this a NOTICE for now so we can link bugs to a libevent versions
diff --git a/src/common/util.c b/src/common/util.c
index b773aa7..2a3aec5 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -155,11 +155,13 @@ tor_malloc_(size_t size DMALLOC_PARAMS)
 #endif
 
   if (PREDICT_UNLIKELY(result == NULL)) {
+    /* LCOV_EXCL_START */
     log_err(LD_MM,"Out of memory on malloc(). Dying.");
     /* If these functions die within a worker process, they won't call
      * spawn_exit, but that's ok, since the parent will run out of memory soon
      * anyway. */
     exit(1);
+    /* LCOV_EXCL_STOP */
   }
   return result;
 }
@@ -243,8 +245,10 @@ tor_realloc_(void *ptr, size_t size DMALLOC_PARAMS)
 #endif
 
   if (PREDICT_UNLIKELY(result == NULL)) {
+    /* LCOV_EXCL_START */
     log_err(LD_MM,"Out of memory on realloc(). Dying.");
     exit(1);
+    /* LCOV_EXCL_STOP */
   }
   return result;
 }
@@ -279,8 +283,10 @@ tor_strdup_(const char *s DMALLOC_PARAMS)
   dup = strdup(s);
 #endif
   if (PREDICT_UNLIKELY(dup == NULL)) {
+    /* LCOV_EXCL_START */
     log_err(LD_MM,"Out of memory on strdup(). Dying.");
     exit(1);
+    /* LCOV_EXCL_STOP */
   }
   return dup;
 }
@@ -3470,13 +3476,17 @@ start_daemon(void)
   start_daemon_called = 1;
 
   if (pipe(daemon_filedes)) {
+    /* LCOV_EXCL_START */
     log_err(LD_GENERAL,"pipe failed; exiting. Error was %s", strerror(errno));
     exit(1);
+    /* LCOV_EXCL_STOP */
   }
   pid = fork();
   if (pid < 0) {
+    /* LCOV_EXCL_START */
     log_err(LD_GENERAL,"fork failed. Exiting.");
     exit(1);
+    /* LCOV_EXCL_STOP */
   }
   if (pid) {  /* Parent */
     int ok;
@@ -3538,8 +3548,10 @@ finish_daemon(const char *desired_cwd)
 
   nullfd = tor_open_cloexec("/dev/null", O_RDWR, 0);
   if (nullfd < 0) {
+    /* LCOV_EXCL_START */
     log_err(LD_GENERAL,"/dev/null can't be opened. Exiting.");
     exit(1);
+    /* LCOV_EXCL_STOP */
   }
   /* close fds linking to invoking terminal, but
    * close usual incoming fds, but redirect them somewhere
@@ -3548,8 +3560,10 @@ finish_daemon(const char *desired_cwd)
   if (dup2(nullfd,0) < 0 ||
       dup2(nullfd,1) < 0 ||
       dup2(nullfd,2) < 0) {
+    /* LCOV_EXCL_START */
     log_err(LD_GENERAL,"dup2 failed. Exiting.");
     exit(1);
+    /* LCOV_EXCL_STOP */
   }
   if (nullfd > 2)
     close(nullfd);
@@ -4324,7 +4338,7 @@ tor_spawn_background(const char *const filename, const char **argv,
 
     _exit(255);
     /* Never reached, but avoids compiler warning */
-    return status;
+    return status; // LCOV_EXCL_LINE
   }
 
   /* In parent */



More information about the tor-commits mailing list