* The usual size for a message is less than 80 bytes.
*
* 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, if a positive 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.
*
* @since 0.12.0
*/
-CK_DLL_EXP void CK_EXPORT check_set_max_msg_size(int max_msg_size);
+CK_DLL_EXP void CK_EXPORT check_set_max_msg_size(size_t max_msg_size);
#ifdef __cplusplus
CK_CPPEND
#endif
/* Maximum size for one message in the message stream. */
-static int ck_max_msg_size = 0;
+static size_t ck_max_msg_size = 0;
#ifndef DEFAULT_MAX_MSG_SIZE
#define DEFAULT_MAX_MSG_SIZE 4096
#endif
* Problems were seen in the wild with up to 4 GB reallocations.
*/
-void check_set_max_msg_size(int max_msg_size) {
- 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 = max_msg_size;
- if (ck_max_msg_size <= 0)
- ck_max_msg_size = DEFAULT_MAX_MSG_SIZE;
- }
+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;
}
-static int get_max_msg_size(void) {
- if (ck_max_msg_size <= 0)
- check_set_max_msg_size(0);
+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;
}
* Run the test suite. This is intended to trigger the "Message is too long" error.
* Actual success/failure is determined by examining the output.
*/
- check_set_max_msg_size(atoi(argv[1]));
+ check_set_max_msg_size(32); // 1st call has no effect since
+ check_set_max_msg_size(atoi(argv[1])); // the 2nd call will override it.
sr = srunner_create(make_set_max_msg_size_suite());
srunner_run_all(sr, CK_NORMAL);
srunner_free(sr);