]> granicus.if.org Git - check/commitdiff
Allow modifying the maximal message size by dynamically changing the environment...
authorOren Ben-Kiki <oren@ben-kiki.org>
Thu, 31 Aug 2017 04:17:43 +0000 (07:17 +0300)
committerOren Ben-Kiki <oren@ben-kiki.org>
Thu, 31 Aug 2017 04:17:43 +0000 (07:17 +0300)
src/check_pack.c

index 4f300e7204c46f4eea3500d60f1d5b7a0de3a2bf..0fe1774c398ba3af8ed87214d8eb32a06f1cc6e6 100644 (file)
@@ -53,21 +53,20 @@ static size_t ck_max_msg_size = 0;
 
 void check_set_max_msg_size(size_t max_msg_size)
 {
-    ck_max_msg_size = 0;
-    char *env = getenv("CK_MAX_MSG_SIZE");
-    if (env)
-        ck_max_msg_size = (size_t)strtoul(env, NULL, 10); // Cast in case size_t != unsigned long.
-    if (ck_max_msg_size == 0)
-        ck_max_msg_size = max_msg_size;
-    if (ck_max_msg_size == 0)
-        ck_max_msg_size = DEFAULT_MAX_MSG_SIZE;
+    ck_max_msg_size = max_msg_size;
 }
 
 static size_t get_max_msg_size(void)
 {
-    if (ck_max_msg_size == 0)      // If check_set_max_msg_size was not called,
-        check_set_max_msg_size(0); // initialize from the environment variable (or default).
-    return ck_max_msg_size;
+    size_t value = 0;
+    char *env = getenv("CK_MAX_MSG_SIZE");
+    if (env)
+        value = (size_t)strtoul(env, NULL, 10); // Cast in case size_t != unsigned long.
+    if (value == 0)
+        value = ck_max_msg_size;
+    if (value == 0)
+        value = DEFAULT_MAX_MSG_SIZE;
+    return value;
 }
 
 /* typedef an unsigned int that has at least 4 bytes */