diff options
| author | jvoisin | 2023-08-21 00:43:30 +0200 |
|---|---|---|
| committer | jvoisin | 2023-08-21 00:43:30 +0200 |
| commit | d9feee06053d1f3c006de00b00dd5feb54ca75e5 (patch) | |
| tree | 6692455e366756429536cb4250db75400ea94fcd | |
| parent | 81527127a9ea5e7db973329b59a5ef7234b05d26 (diff) | |
Add tests for fgetws and mbsrtowcs
| -rw-r--r-- | include/wchar.h | 2 | ||||
| -rw-r--r-- | tests/Makefile | 4 | ||||
| -rw-r--r-- | tests/test_fgetws_dynamic.c | 15 | ||||
| -rw-r--r-- | tests/test_fgetws_static.c | 15 | ||||
| -rw-r--r-- | tests/test_mbsrtowcs_dynamic.c | 16 | ||||
| -rw-r--r-- | tests/test_mbsrtowcs_static.c | 16 |
6 files changed, 67 insertions, 1 deletions
diff --git a/include/wchar.h b/include/wchar.h index 89ae539..4ca49e8 100644 --- a/include/wchar.h +++ b/include/wchar.h | |||
| @@ -229,7 +229,7 @@ _FORTIFY_FN(wcsrtombs) size_t wcsrtombs(char * _FORTIFY_POS0 __d, | |||
| 229 | return __r; | 229 | return __r; |
| 230 | } | 230 | } |
| 231 | 231 | ||
| 232 | __access(write_only, 2, 3) | 232 | __access(write_only, 1, 3) |
| 233 | __diagnose_as_builtin(__builtin_wcstombs, 1, 2, 3) | 233 | __diagnose_as_builtin(__builtin_wcstombs, 1, 2, 3) |
| 234 | _FORTIFY_FN(wcstombs) size_t wcstombs(char * _FORTIFY_POS0 __s, | 234 | _FORTIFY_FN(wcstombs) size_t wcstombs(char * _FORTIFY_POS0 __s, |
| 235 | const wchar_t *__ws, size_t __n) | 235 | const wchar_t *__ws, size_t __n) |
diff --git a/tests/Makefile b/tests/Makefile index bcce585..5145b3b 100644 --- a/tests/Makefile +++ b/tests/Makefile | |||
| @@ -15,6 +15,8 @@ TARGETS= \ | |||
| 15 | test_confstr_static \ | 15 | test_confstr_static \ |
| 16 | test_fgets_dynamic \ | 16 | test_fgets_dynamic \ |
| 17 | test_fgets_static \ | 17 | test_fgets_static \ |
| 18 | test_fgetws_dynamic \ | ||
| 19 | test_fgetws_static \ | ||
| 18 | test_fread_int_overflow \ | 20 | test_fread_int_overflow \ |
| 19 | test_fread_overwrite_dynamic \ | 21 | test_fread_overwrite_dynamic \ |
| 20 | test_fread_overwrite_static \ | 22 | test_fread_overwrite_static \ |
| @@ -31,6 +33,8 @@ TARGETS= \ | |||
| 31 | test_gethostname_static \ | 33 | test_gethostname_static \ |
| 32 | test_getlogin_r_dynamic \ | 34 | test_getlogin_r_dynamic \ |
| 33 | test_getlogin_r_static \ | 35 | test_getlogin_r_static \ |
| 36 | test_mbsrtowcs_dynamic \ | ||
| 37 | test_mbsrtowcs_static \ | ||
| 34 | test_memchr_dynamic_read \ | 38 | test_memchr_dynamic_read \ |
| 35 | test_memchr_static_read \ | 39 | test_memchr_static_read \ |
| 36 | test_memcpy_dynamic_read \ | 40 | test_memcpy_dynamic_read \ |
diff --git a/tests/test_fgetws_dynamic.c b/tests/test_fgetws_dynamic.c new file mode 100644 index 0000000..f5919da --- /dev/null +++ b/tests/test_fgetws_dynamic.c | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #define _GNU_SOURCE | ||
| 4 | #include <wchar.h> | ||
| 5 | |||
| 6 | int main(int argc, char** argv) { | ||
| 7 | wchar_t buffer[8] = {L'A'}; | ||
| 8 | |||
| 9 | CHK_FAIL_START | ||
| 10 | fgetws(buffer, argc, NULL); | ||
| 11 | CHK_FAIL_END | ||
| 12 | |||
| 13 | putwchar(buffer[0]); | ||
| 14 | return ret; | ||
| 15 | } | ||
diff --git a/tests/test_fgetws_static.c b/tests/test_fgetws_static.c new file mode 100644 index 0000000..a02653f --- /dev/null +++ b/tests/test_fgetws_static.c | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #define _GNU_SOURCE | ||
| 4 | #include <wchar.h> | ||
| 5 | |||
| 6 | int main(int argc, char** argv) { | ||
| 7 | wchar_t buffer[12] = {L'A'}; | ||
| 8 | |||
| 9 | CHK_FAIL_START | ||
| 10 | fgetws(buffer, 14, NULL); | ||
| 11 | CHK_FAIL_END | ||
| 12 | |||
| 13 | putwchar(buffer[0]); | ||
| 14 | return ret; | ||
| 15 | } | ||
diff --git a/tests/test_mbsrtowcs_dynamic.c b/tests/test_mbsrtowcs_dynamic.c new file mode 100644 index 0000000..21b7eab --- /dev/null +++ b/tests/test_mbsrtowcs_dynamic.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #define _GNU_SOURCE | ||
| 4 | #include <wchar.h> | ||
| 5 | |||
| 6 | int main(int argc, char** argv) { | ||
| 7 | wchar_t dest[3]; | ||
| 8 | const char* src = "abcdefghijklmnopq"; | ||
| 9 | mbstate_t ps; | ||
| 10 | |||
| 11 | CHK_FAIL_START | ||
| 12 | mbsrtowcs(dest, &src, argc, &ps); | ||
| 13 | CHK_FAIL_END | ||
| 14 | |||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_mbsrtowcs_static.c b/tests/test_mbsrtowcs_static.c new file mode 100644 index 0000000..896329a --- /dev/null +++ b/tests/test_mbsrtowcs_static.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #define _GNU_SOURCE | ||
| 4 | #include <wchar.h> | ||
| 5 | |||
| 6 | int main(int argc, char** argv) { | ||
| 7 | wchar_t dest[3]; | ||
| 8 | const char* src = "abcdefghijklmnopq"; | ||
| 9 | mbstate_t ps; | ||
| 10 | |||
| 11 | CHK_FAIL_START | ||
| 12 | mbsrtowcs(dest, &src, 12, &ps); | ||
| 13 | CHK_FAIL_END | ||
| 14 | |||
| 15 | return ret; | ||
| 16 | } | ||
