]> git.saurik.com Git - apple/libc.git/blob - tests/wchar.c
Libc-1158.50.2.tar.gz
[apple/libc.git] / tests / wchar.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <wchar.h>
5
6 #include <darwintest.h>
7
8 /*
9 * Test courtesy of Roel Standaert
10 * Source: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=209907
11 */
12 T_DECL(PR_26556792, "wcsrtombs neglects to set src pointer on EILSEQ error")
13 {
14 char out[64];
15 wchar_t *in = L"Hello! \x20AC Hello!";
16 const wchar_t *inptr = in;
17 mbstate_t state = {{0}};
18
19 T_ASSERT_EQ((size_t)-1, wcsrtombs(out, &inptr, sizeof(out), &state), NULL);
20 T_EXPECT_EQ((long)(inptr - in), (long)7, NULL);
21 }
22
23
24 T_DECL(PR_26828480, "double free in __vfwprintf")
25 {
26 wchar_t *test;
27 int ret;
28
29 test = (wchar_t *) malloc(512 * sizeof(wchar_t));
30 ret = swprintf(test, 512, L"%a, %s\n", 3.14, (char *) NULL);
31
32 free(test);
33 T_ASSERT_GT(ret, 0, "swprintf");
34 }