diff options
Diffstat (limited to 'tests/test_strncat_n_one.c')
| -rw-r--r-- | tests/test_strncat_n_one.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/test_strncat_n_one.c b/tests/test_strncat_n_one.c new file mode 100644 index 0000000..fce46bd --- /dev/null +++ b/tests/test_strncat_n_one.c | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | char buffer[8] = {0}; | ||
| 7 | strncat(buffer, "1234567", 7); | ||
| 8 | puts(buffer); | ||
| 9 | |||
| 10 | /* n=1, buffer has 7 chars ("1234567"). | ||
| 11 | * 7+1+1 = 9 > 8 → overflow. Even n=1 can overflow a nearly-full buffer. */ | ||
| 12 | CHK_FAIL_START | ||
| 13 | strncat(buffer, "X", 1); | ||
| 14 | CHK_FAIL_END | ||
| 15 | |||
| 16 | puts(buffer); | ||
| 17 | return ret; | ||
| 18 | } | ||
