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

[tor-commits] [tor/release-0.3.3] Call strlen() once



commit 5986589b48de6addf99436df1feeea1362767acb
Author: rl1987 <rl1987@xxxxxxxxxxxxxxxx>
Date:   Mon Feb 12 21:08:17 2018 +0100

    Call strlen() once
---
 src/common/util.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/common/util.c b/src/common/util.c
index ea0ec3dae..d8891c6a5 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1081,12 +1081,13 @@ string_is_valid_dest(const char *string)
 {
   char *tmp = NULL;
   int retval;
+  size_t len = strlen(string);
 
   tor_assert(string);
-  tor_assert(strlen(string) > 0);
+  tor_assert(len > 0);
 
-  if (string[0] == '[' && string[strlen(string) - 1] == ']')
-    string = tmp = tor_strndup(string + 1, strlen(string) - 2);
+  if (string[0] == '[' && string[len - 1] == ']')
+    string = tmp = tor_strndup(string + 1, len - 2);
 
   retval = string_is_valid_ipv4_address(string) ||
     string_is_valid_ipv6_address(string) ||



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