From: Oren Ben-Kiki Date: Sun, 27 Aug 2017 18:54:52 +0000 (+0300) Subject: Document the new function, give precedence to environment. X-Git-Tag: 0.12.0~3^2~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bb91bc23c19253cf156914af97d10385c92142f1;p=check Document the new function, give precedence to environment. --- diff --git a/doc/check.texi b/doc/check.texi index 2421963..c8afba5 100644 --- a/doc/check.texi +++ b/doc/check.texi @@ -993,6 +993,17 @@ repetitive code that is hard to read. For your convenience Check provides a set of functions (actually macros) for testing often used conditions. +@findex check_set_max_msg_size +@vindex CK_MAX_MSG_SIZE +The typical size of an assertion message is less than 80 bytes. +However, some of the functions listed below can generate very large messages +(up to 4GB allocations were seen in the wild). +To prevent this, a limit is placed on the assertion message size. +This limit is 4K bytes by default. +It can be modified by setting the @code(CK_MAX_MSG_SIZE) environment variable, +or, if it is not set, by invoking the @code{check_set_max_msg_size()} function. +If used, this function must be called, once, before the first assertion. + @ftable @code @item ck_abort Unconditionally fails test with default message. @@ -2274,6 +2285,8 @@ CK_XML_LOG_FILE_NAME: Filename to write XML log to. See section @ref{XML Logging CK_TAP_LOG_FILE_NAME: Filename to write TAP (Test Anything Protocol) output to. See section @ref{TAP Logging}. +CK_MAX_MSG_SIZE: Maximal assertion message size. + @node Copying This Manual, Index, Environment Variable Reference, Top @appendix Copying This Manual diff --git a/src/check.h.in b/src/check.h.in index 46e9c4b..458e3d1 100644 --- a/src/check.h.in +++ b/src/check.h.in @@ -2271,12 +2271,11 @@ CK_DLL_EXP void CK_EXPORT check_waitpid_and_exit(pid_t pid) CK_ATTRIBUTE_NORETUR * (values of up to 4GB were seen in the wild). * The usual size for a message is less than 80 bytes. * - * By default, an assertion message is restricted to 4K bytes. - * It is possible to override this by setting the CK_MAX_MSG_SIZE environment variable, - * or by invoking this function. - * Specifying a non-positive argument resets the value, - * to the value specified by the environment variable, - * or to the default 4K bytes if the environment variable is not specified. + * If the environment variable CK_MAX_MSG_SIZE is defined to a positive value, it is used. + * Otherwise, if a maximal message size is set via this function, it is used. + * Otherwise, the maximal message size is one assigned at compile time (4K bytes). + * + * If used, this function must be called once before any assertion is made. * * @param max_msg_size the maximal assertion message size. * diff --git a/src/check_pack.c b/src/check_pack.c index 88a1050..c1b77f2 100644 --- a/src/check_pack.c +++ b/src/check_pack.c @@ -23,7 +23,6 @@ #include #include #include - #include "check.h" #include "check_error.h" #include "check_list.h" @@ -39,6 +38,9 @@ /* Maximum size for one message in the message stream. */ static int ck_max_msg_size = 0; +#ifndef DEFAULT_MAX_MSG_SIZE +#define DEFAULT_MAX_MSG_SIZE 4096 +#endif /* This is used to implement a sliding window on the receiving * side. When sending messages, we assure that no single message * is bigger than this. @@ -49,22 +51,22 @@ static int ck_max_msg_size = 0; */ void check_set_max_msg_size(int max_msg_size) { - ck_max_msg_size = max_msg_size; -} - -static int get_max_msg_size(void) { if (ck_max_msg_size <= 0) { char *env = getenv("CK_MAX_MSG_SIZE"); if (env) ck_max_msg_size = atoi(env); - if (ck_max_msg_size <= 0) - ck_max_msg_size = 4096; + ck_max_msg_size = max_msg_size; + if (ck_max_msg_size <= 0) + ck_max_msg_size = DEFAULT_MAX_MSG_SIZE; } - return ck_max_msg_size; } - +static int get_max_msg_size(void) { + if (ck_max_msg_size <= 0) + check_set_max_msg_size(0); + return ck_max_msg_size; +} /* typedef an unsigned int that has at least 4 bytes */ typedef uint32_t ck_uint32;