summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorjvoisin2023-06-22 17:58:58 +0200
committerjvoisin2023-06-22 17:58:58 +0200
commitaf7480d0190cb5dcf279a7ddfab320ff084a3471 (patch)
tree3ba3190adb08bd5d3a4671358c5ae4c3c13f3ab2 /tests
parentcb1ce9e1815a492de0f13c2b046b8472024b9f6d (diff)
Add tests for stpcpy
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile7
-rw-r--r--tests/test_stpcpy_overwrite_over.c15
-rw-r--r--tests/test_stpcpy_overwrite_under.c15
-rw-r--r--tests/test_stpcpy_static_write.c16
4 files changed, 51 insertions, 2 deletions
diff --git a/tests/Makefile b/tests/Makefile
index 80a4626..6722add 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -12,13 +12,16 @@ TARGETS=test_memcpy_static_write \
12 test_memmove_dynamic_read \ 12 test_memmove_dynamic_read \
13 test_memset_static_write \ 13 test_memset_static_write \
14 test_memset_dynamic_write \ 14 test_memset_dynamic_write \
15 test_strcpy_static_write \ 15 test_stpcpy_overwrite_over \
16 test_stpcpy_overwrite_under \
17 test_stpcpy_static_write \
16 test_strcat_static_write \ 18 test_strcat_static_write \
17 test_strcpy_overwrite_over \ 19 test_strcpy_overwrite_over \
18 test_strcpy_overwrite_under \ 20 test_strcpy_overwrite_under \
19 test_strncpy_static_write \ 21 test_strcpy_static_write \
20 test_strncpy_overwrite_over \ 22 test_strncpy_overwrite_over \
21 test_strncpy_overwrite_under \ 23 test_strncpy_overwrite_under \
24 test_strncpy_static_write \
22 test_getcwd \ 25 test_getcwd \
23 26
24.SILENT: 27.SILENT:
diff --git a/tests/test_stpcpy_overwrite_over.c b/tests/test_stpcpy_overwrite_over.c
new file mode 100644
index 0000000..b7cbedc
--- /dev/null
+++ b/tests/test_stpcpy_overwrite_over.c
@@ -0,0 +1,15 @@
1#include "common.h"
2
3#include <string.h>
4
5int main(int argc, char** argv) {
6 char buffer[9] = {'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', '\0'};
7 puts(buffer);
8
9 CHK_FAIL_START
10 stpcpy(buffer+1, buffer);
11 CHK_FAIL_END
12
13 puts(buffer);
14 return ret;
15}
diff --git a/tests/test_stpcpy_overwrite_under.c b/tests/test_stpcpy_overwrite_under.c
new file mode 100644
index 0000000..2759e5d
--- /dev/null
+++ b/tests/test_stpcpy_overwrite_under.c
@@ -0,0 +1,15 @@
1#include "common.h"
2
3#include <string.h>
4
5int main(int argc, char** argv) {
6 char buffer[9] = {'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', '\0'};
7 puts(buffer);
8
9 CHK_FAIL_START
10 stpcpy(buffer-1, buffer);
11 CHK_FAIL_END
12
13 puts(buffer);
14 return ret;
15}
diff --git a/tests/test_stpcpy_static_write.c b/tests/test_stpcpy_static_write.c
new file mode 100644
index 0000000..4aa4aee
--- /dev/null
+++ b/tests/test_stpcpy_static_write.c
@@ -0,0 +1,16 @@
1#include "common.h"
2
3#include <string.h>
4
5int main(int argc, char** argv) {
6 char buffer[8] = {0};
7 strcpy(buffer, "1234567");
8 puts(buffer);
9
10 CHK_FAIL_START
11 stpcpy(buffer, "1234567890");
12 CHK_FAIL_END
13
14 puts(buffer);
15 return ret;
16}