Created
August 30, 2013 12:47
-
-
Save nxg/6389474 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "lcut.h" | |
void tc_longstring_test(lcut_tc_t *tc, void *data) { | |
char s1[] = "abc"; | |
char s2[] = /* 200 characters: longer than LCUT_MAX_STR_LEN */ | |
"0123456789012345678901234567890123456789" | |
"0123456789012345678901234567890123456789" | |
"0123456789012345678901234567890123456789" | |
"0123456789012345678901234567890123456789" | |
"0123456789012345678901234567890123456789"; | |
LCUT_STR_EQUAL(tc, s1, s2); | |
} | |
void tc_simple_test(lcut_tc_t *tc, void *data) { | |
char s1[] = "abc"; | |
char s2[] = "def"; | |
LCUT_STR_EQUAL(tc, s1, s2); | |
} | |
int main() { | |
lcut_ts_t *suite = NULL; | |
LCUT_TEST_BEGIN("A Trivial test", NULL, NULL); | |
LCUT_TS_INIT(suite, "A Trivial test suite", NULL, NULL); | |
LCUT_TC_ADD(suite, "A long-string case", tc_longstring_test, NULL, NULL, NULL); | |
LCUT_TC_ADD(suite, "A simple", tc_simple_test, NULL, NULL, NULL); | |
LCUT_TS_ADD(suite); | |
LCUT_TEST_RUN(); | |
LCUT_TEST_REPORT(); | |
LCUT_TEST_END(); | |
LCUT_TEST_RESULT(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r 380791d366ff -r 533743692764 src/c/test/lcut/lcut.c | |
--- a/src/c/test/lcut/lcut.c Fri Aug 30 13:19:05 2013 +0100 | |
+++ b/src/c/test/lcut/lcut.c Fri Aug 30 13:26:01 2013 +0100 | |
@@ -32,10 +32,10 @@ | |
} while(0) | |
#define FILL_IN_FAILED_REASON(tc, fname, fcname, lineno, reason_fmt, ...) do { \ | |
- sprintf((tc)->fname, "%s", (fname)); \ | |
- sprintf((tc)->fcname, "%s", (fcname)); \ | |
+ snprintf((tc)->fname, LCUT_MAX_NAME_LEN, "%s", (fname)); \ | |
+ snprintf((tc)->fcname, LCUT_MAX_NAME_LEN, "%s", (fcname)); \ | |
(tc)->line = (lineno); \ | |
- sprintf((tc)->reason, (reason_fmt), __VA_ARGS__); \ | |
+ snprintf((tc)->reason, LCUT_MAX_STR_LEN, (reason_fmt), __VA_ARGS__); \ | |
(tc)->status = TEST_CASE_FAILURE; \ | |
} while (0) | |
@@ -391,7 +391,7 @@ | |
exit(EXIT_FAILURE); | |
} | |
memset(s, 0, sizeof(*s)); | |
- strcpy(s->desc, symbol_name); | |
+ strncpy(s->desc, symbol_name, LCUT_MAX_NAME_LEN); | |
s->obj_type = obj_type; | |
APR_RING_INIT(&(s->value_list), lcut_value_t, link); | |
APR_RING_INSERT_TAIL(&_symbol_list, s, lcut_symbol_t, link); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment