[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] const-ify the new failure vars, and one old one



commit 3a68f2f54ed67176a8ed0b7aa276ef58a54b26db
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Fri Mar 13 09:41:49 2015 -0400

    const-ify the new failure vars, and one old one
---
 src/common/compat_pthreads.c |   13 ++++++-------
 src/or/control.c             |    2 +-
 src/or/rendservice.c         |    2 +-
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/common/compat_pthreads.c b/src/common/compat_pthreads.c
index 70259a8..fdc5046 100644
--- a/src/common/compat_pthreads.c
+++ b/src/common/compat_pthreads.c
@@ -91,10 +91,9 @@ static pthread_mutexattr_t attr_recursive;
 void
 tor_mutex_init(tor_mutex_t *mutex)
 {
-  int err;
   if (PREDICT_UNLIKELY(!threads_initialized))
     tor_threads_init();
-  err = pthread_mutex_init(&mutex->mutex, &attr_recursive);
+  const int err = pthread_mutex_init(&mutex->mutex, &attr_recursive);
   if (PREDICT_UNLIKELY(err)) {
     log_err(LD_GENERAL, "Error %d creating a mutex.", err);
     tor_fragile_assert();
@@ -276,16 +275,16 @@ void
 tor_threads_init(void)
 {
   if (!threads_initialized) {
-    int ret;
     pthread_mutexattr_init(&attr_recursive);
     pthread_mutexattr_settype(&attr_recursive, PTHREAD_MUTEX_RECURSIVE);
-    ret = pthread_attr_init(&attr_detached);
-    tor_assert(ret == 0);
+    const int ret1 = pthread_attr_init(&attr_detached);
+    tor_assert(ret1 == 0);
 #ifndef PTHREAD_CREATE_DETACHED
 #define PTHREAD_CREATE_DETACHED 1
 #endif
-    ret = pthread_attr_setdetachstate(&attr_detached, PTHREAD_CREATE_DETACHED);
-    tor_assert(ret == 0);
+    const int ret2 =
+      pthread_attr_setdetachstate(&attr_detached, PTHREAD_CREATE_DETACHED);
+    tor_assert(ret2 == 0);
     threads_initialized = 1;
     set_main_thread();
   }
diff --git a/src/or/control.c b/src/or/control.c
index 819a57f..34d539b 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -3102,7 +3102,7 @@ handle_control_authchallenge(control_connection_t *conn, uint32_t len,
     tor_free(client_nonce);
     return -1;
   }
-  int fail = crypto_rand(server_nonce, SAFECOOKIE_SERVER_NONCE_LEN);
+  const int fail = crypto_rand(server_nonce, SAFECOOKIE_SERVER_NONCE_LEN);
   tor_assert(!fail);
 
   /* Now compute and send the server-to-controller response, and the
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index 77eaea0..eb2748c 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -3320,7 +3320,7 @@ rend_services_introduce(void)
       intro = tor_malloc_zero(sizeof(rend_intro_point_t));
       intro->extend_info = extend_info_from_node(node, 0);
       intro->intro_key = crypto_pk_new();
-      int fail = crypto_pk_generate_key(intro->intro_key);
+      const int fail = crypto_pk_generate_key(intro->intro_key);
       tor_assert(!fail);
       intro->time_published = -1;
       intro->time_to_expire = -1;

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits