1570af302Sopenharmony_ci// commit 211264e46a2f1bc382a84435e904d1548de672b0 2013-09-27 2570af302Sopenharmony_ci// mbsrtowcs should not write outside the ws array 3570af302Sopenharmony_ci#include <wchar.h> 4570af302Sopenharmony_ci#include "test.h" 5570af302Sopenharmony_ci 6570af302Sopenharmony_ciint main(void) 7570af302Sopenharmony_ci{ 8570af302Sopenharmony_ci wchar_t ws[] = L"XXXXX"; 9570af302Sopenharmony_ci const char *src = "abcd"; 10570af302Sopenharmony_ci const char *want = src + 4; 11570af302Sopenharmony_ci size_t r; 12570af302Sopenharmony_ci 13570af302Sopenharmony_ci r = mbsrtowcs(ws, &src, 4, 0); 14570af302Sopenharmony_ci if (r != 4) 15570af302Sopenharmony_ci t_error("mbsrtowcs(ws, &abcd, 4, 0) returned %zu, wanted 4\n", r); 16570af302Sopenharmony_ci if (src != want) 17570af302Sopenharmony_ci t_error("mbsrtowcs(ws, &abcd, 4, 0) set abcd to %p wanted %p\n", src, want); 18570af302Sopenharmony_ci if (wcscmp(ws, L"abcdX") != 0) 19570af302Sopenharmony_ci t_error("ws is L\"%ls\", wanted L\"abcdX\"\n", ws); 20570af302Sopenharmony_ci 21570af302Sopenharmony_ci return t_status; 22570af302Sopenharmony_ci} 23