summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjvoisin2026-04-30 17:50:27 +0200
committerjvoisin2026-04-30 17:50:27 +0200
commitdfdf53df99c8f59e5e3a4296c455041bee96a88d (patch)
tree32b8a50c11c708b69874444c4d0969d40d0d7434
parentf9239e2c0f0be9856322727887a45333683940a6 (diff)
Improve coverage for wmemcpy and wmemmove
Like it's already done for memcpy and memmove. Add tests as well, to prove that nothing broke.
Diffstat (limited to '')
-rw-r--r--include/wchar.h16
-rw-r--r--tests/Makefile4
-rw-r--r--tests/test_wmemcpy_dynamic_read.c16
-rw-r--r--tests/test_wmemcpy_static_read.c16
-rw-r--r--tests/test_wmemmove_dynamic_read.c16
-rw-r--r--tests/test_wmemmove_static_read.c16
6 files changed, 78 insertions, 6 deletions
diff --git a/include/wchar.h b/include/wchar.h
index 0842115..9e32720 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -221,21 +221,25 @@ _FORTIFY_FN(wcstombs) size_t wcstombs(char * _FORTIFY_POS0 __s,
221} 221}
222 222
223_FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t * _FORTIFY_POS0 __d, 223_FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t * _FORTIFY_POS0 __d,
224 const wchar_t *__s, size_t __n) 224 const wchar_t * _FORTIFY_POS0 __s,
225 size_t __n)
225{ 226{
226 size_t __b = __bos(__d, 0); 227 size_t __bd = __bos(__d, 0);
228 size_t __bs = __bos(__s, 0);
227 229
228 if (__n > __b / sizeof(wchar_t)) 230 if (__n > __bd / sizeof(wchar_t) || __n > __bs / sizeof(wchar_t))
229 __builtin_trap(); 231 __builtin_trap();
230 return __orig_wmemcpy(__d, __s, __n); 232 return __orig_wmemcpy(__d, __s, __n);
231} 233}
232 234
233_FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t * _FORTIFY_POS0 __d, 235_FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t * _FORTIFY_POS0 __d,
234 const wchar_t *__s, size_t __n) 236 const wchar_t * _FORTIFY_POS0 __s,
237 size_t __n)
235{ 238{
236 size_t __b = __bos(__d, 0); 239 size_t __bd = __bos(__d, 0);
240 size_t __bs = __bos(__s, 0);
237 241
238 if (__n > __b / sizeof(wchar_t)) 242 if (__n > __bd / sizeof(wchar_t) || __n > __bs / sizeof(wchar_t))
239 __builtin_trap(); 243 __builtin_trap();
240 return __orig_wmemmove(__d, __s, __n); 244 return __orig_wmemmove(__d, __s, __n);
241} 245}
diff --git a/tests/Makefile b/tests/Makefile
index adea381..fbfd178 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -100,9 +100,13 @@ RUNTIME_TARGETS= \
100 test_wcscpy_static_write \ 100 test_wcscpy_static_write \
101 test_wcsncat_static_write \ 101 test_wcsncat_static_write \
102 test_wcsncpy_static_write \ 102 test_wcsncpy_static_write \
103 test_wmemcpy_dynamic_read \
103 test_wmemcpy_dynamic_write \ 104 test_wmemcpy_dynamic_write \
105 test_wmemcpy_static_read \
104 test_wmemcpy_static_write \ 106 test_wmemcpy_static_write \
107 test_wmemmove_dynamic_read \
105 test_wmemmove_dynamic_write \ 108 test_wmemmove_dynamic_write \
109 test_wmemmove_static_read \
106 test_wmemmove_static_write \ 110 test_wmemmove_static_write \
107 test_wmemset_dynamic \ 111 test_wmemset_dynamic \
108 test_wmemset_static \ 112 test_wmemset_static \
diff --git a/tests/test_wmemcpy_dynamic_read.c b/tests/test_wmemcpy_dynamic_read.c
new file mode 100644
index 0000000..20ba0ad
--- /dev/null
+++ b/tests/test_wmemcpy_dynamic_read.c
@@ -0,0 +1,16 @@
1#include "common.h"
2
3#include <wchar.h>
4
5int main(int argc, char** argv) {
6 wchar_t buffer[12] = {0};
7 wmemcpy(buffer, L"αβγδεζηθικ", sizeof(buffer) / sizeof(wchar_t) - 1);
8 printf("%ls\n", buffer);
9
10 CHK_FAIL_START
11 wmemcpy(buffer, L"αβγδεζ", argc);
12 CHK_FAIL_END
13
14 printf("%ls\n", buffer);
15 return ret;
16}
diff --git a/tests/test_wmemcpy_static_read.c b/tests/test_wmemcpy_static_read.c
new file mode 100644
index 0000000..c87d378
--- /dev/null
+++ b/tests/test_wmemcpy_static_read.c
@@ -0,0 +1,16 @@
1#include "common.h"
2
3#include <wchar.h>
4
5int main(int argc, char** argv) {
6 wchar_t buffer[8] = {0};
7 wmemcpy(buffer, L"αβγδεζ", 4);
8 printf("%ls\n", buffer);
9
10 CHK_FAIL_START
11 wmemcpy(buffer, L"αβγδεζ", sizeof(buffer) / sizeof(wchar_t));
12 CHK_FAIL_END
13
14 printf("%ls\n", buffer);
15 return ret;
16}
diff --git a/tests/test_wmemmove_dynamic_read.c b/tests/test_wmemmove_dynamic_read.c
new file mode 100644
index 0000000..05e315b
--- /dev/null
+++ b/tests/test_wmemmove_dynamic_read.c
@@ -0,0 +1,16 @@
1#include "common.h"
2
3#include <wchar.h>
4
5int main(int argc, char** argv) {
6 wchar_t buffer[12] = {0};
7 wmemmove(buffer, L"αβγδεζηθικ", sizeof(buffer) / sizeof(wchar_t) - 1);
8 printf("%ls\n", buffer);
9
10 CHK_FAIL_START
11 wmemmove(buffer, L"αβγδεζ", argc);
12 CHK_FAIL_END
13
14 printf("%ls\n", buffer);
15 return ret;
16}
diff --git a/tests/test_wmemmove_static_read.c b/tests/test_wmemmove_static_read.c
new file mode 100644
index 0000000..6e4a929
--- /dev/null
+++ b/tests/test_wmemmove_static_read.c
@@ -0,0 +1,16 @@
1#include "common.h"
2
3#include <wchar.h>
4
5int main(int argc, char** argv) {
6 wchar_t buffer[8] = {0};
7 wmemmove(buffer, L"αβγδεζ", 4);
8 printf("%ls\n", buffer);
9
10 CHK_FAIL_START
11 wmemmove(buffer, L"αβγδεζ", sizeof(buffer) / sizeof(wchar_t));
12 CHK_FAIL_END
13
14 printf("%ls\n", buffer);
15 return ret;
16}