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.
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
* (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.
*
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-
#include "check.h"
#include "check_error.h"
#include "check_list.h"
/* 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.
*/
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;