From: Oren Ben-Kiki Date: Thu, 31 Aug 2017 04:17:43 +0000 (+0300) Subject: Allow modifying the maximal message size by dynamically changing the environment... X-Git-Tag: 0.12.0~3^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=253678a5546963c9d4c8bd2370412063ed129ee3;p=check Allow modifying the maximal message size by dynamically changing the environment variable. --- diff --git a/src/check_pack.c b/src/check_pack.c index 4f300e7..0fe1774 100644 --- a/src/check_pack.c +++ b/src/check_pack.c @@ -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 */