summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjvoisin2023-04-13 22:46:49 +0200
committerjvoisin2023-04-13 23:49:02 +0200
commitaceef734bdfe4f68e2227fc9ac636aae8235fa12 (patch)
treeab149e47157fc9f167d92685b586235d2fb60d3d
parent476fbfc29fe843cf362a2e203818cbe1a97130bb (diff)
Add tests for memmove
-rw-r--r--tests/Makefile12
-rw-r--r--tests/test_memmove_dynamic_read.c16
-rw-r--r--tests/test_memmove_dynamic_write.c16
-rw-r--r--tests/test_memmove_static_read.c16
-rw-r--r--tests/test_memmove_static_write.c16
5 files changed, 72 insertions, 4 deletions
diff --git a/tests/Makefile b/tests/Makefile
index c48d0b0..1f80c32 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,10 +1,14 @@
1CC=../x86_64-linux-musl-native/bin/gcc 1CC=../x86_64-linux-musl-native/bin/gcc
2CFLAGS=-I../include/ -D_FORTIFY_SOURCE=3 -static -O2 2CFLAGS=-I../include/ -D_FORTIFY_SOURCE=3 -static -O2
3 3
4TARGETS=test_memcpy_static_write \ 4TARGETS=test_memcpy_static_write \
5 test_memcpy_dynamic_write \ 5 test_memcpy_dynamic_write \
6 test_memcpy_static_read \ 6 test_memcpy_static_read \
7 test_memcpy_dynamic_read 7 test_memcpy_dynamic_read \
8 test_memmove_static_write \
9 test_memmove_dynamic_write \
10 test_memmove_static_read \
11 test_memmove_dynamic_read
8 12
9.SILENT: 13.SILENT:
10 14
diff --git a/tests/test_memmove_dynamic_read.c b/tests/test_memmove_dynamic_read.c
new file mode 100644
index 0000000..1a01925
--- /dev/null
+++ b/tests/test_memmove_dynamic_read.c
@@ -0,0 +1,16 @@
1#include "common.h"
2
3#include <string.h>
4
5int main(int argc, char** argv) {
6 char buffer[12] = {0};
7 memmove(buffer, "1234567890", sizeof(buffer) - 1);
8 puts(buffer);
9
10 CHK_FAIL_START
11 memmove(buffer, "123456", argc);
12 CHK_FAIL_END
13
14 puts(buffer);
15 return ret;
16}
diff --git a/tests/test_memmove_dynamic_write.c b/tests/test_memmove_dynamic_write.c
new file mode 100644
index 0000000..b62c01f
--- /dev/null
+++ b/tests/test_memmove_dynamic_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 memmove(buffer, "1234567890", sizeof(buffer) - 1);
8 puts(buffer);
9
10 CHK_FAIL_START
11 memmove(buffer, "1234567890", argc);
12 CHK_FAIL_END
13
14 puts(buffer);
15 return ret;
16}
diff --git a/tests/test_memmove_static_read.c b/tests/test_memmove_static_read.c
new file mode 100644
index 0000000..fb128a6
--- /dev/null
+++ b/tests/test_memmove_static_read.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 memmove(buffer, "123456", 4);
8 puts(buffer);
9
10 CHK_FAIL_START
11 memmove(buffer, "123456", sizeof(buffer));
12 CHK_FAIL_END
13
14 puts(buffer);
15 return ret;
16}
diff --git a/tests/test_memmove_static_write.c b/tests/test_memmove_static_write.c
new file mode 100644
index 0000000..711f449
--- /dev/null
+++ b/tests/test_memmove_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 memmove(buffer, "1234567890", sizeof(buffer) - 1);
8 puts(buffer);
9
10 CHK_FAIL_START
11 memmove(buffer, "1234567890", sizeof(buffer) + 1);
12 CHK_FAIL_END
13
14 puts(buffer);
15 return ret;
16}