calls to cuserid() can result in buffer overruns and/or overflows
[glibc.git] / localedata / tst-strptime.c
blobbc2c7f1b64de0090a03e1c4f17d1382cc47ed367
1 #include <locale.h>
2 #include <time.h>
3 #include <stdio.h>
4 #include <string.h>
6 static int
7 do_test (void)
9 int result = 0;
11 if (setlocale (LC_ALL, "vi_VN.TCVN5712-1") == NULL)
13 puts ("cannot set locale");
14 return 1;
16 struct tm tm;
17 memset (&tm, '\0', sizeof (tm));
18 /* This is November in Vietnamese encoded using TCVN5712-1. */
19 static const char s[] = "\
20 \x54\x68\xb8\x6e\x67\x20\x6d\xad\xea\x69\x20\x6d\xe9\x74\0";
21 char *r = strptime (s, "%b", &tm);
22 printf ("r = %p, r-s = %tu, tm.tm_mon = %d\n", r, r - s, tm.tm_mon);
23 result = r == NULL || r - s != 14 || tm.tm_mon != 10;
25 if (setlocale (LC_ALL, "ja_JP.UTF-8") == NULL)
27 puts ("cannot set locale");
28 return 1;
30 static const char s2[] = "\
31 \x32\x35\x20\x30\x36\x20\xe5\xb9\xb3\xe6\x88\x90\x32\x30\0";
32 memset (&tm, '\0', sizeof (tm));
33 r = strptime (s2, "%d %m %EC%Ey", &tm);
34 printf ("\
35 r = %p, r-s2 = %tu, tm.tm_mday = %d, tm.tm_mon = %d, tm.tm_year = %d\n",
36 r, r - s2, tm.tm_mday, tm.tm_mon, tm.tm_year);
37 result |= (r == NULL || r - s2 != 14 || tm.tm_mday != 25 || tm.tm_mon != 5
38 || tm.tm_year != 108);
40 static const char s3[] = "\
41 \x32\x35\x20\x30\x36\x20\xe5\xb9\xb3\xe6\x88\x90\x32\x30\xe5\xb9\xb4\0";
42 memset (&tm, '\0', sizeof (tm));
43 r = strptime (s3, "%d %m %EY", &tm);
44 printf ("\
45 r = %p, r-s3 = %tu, tm.tm_mday = %d, tm.tm_mon = %d, tm.tm_year = %d\n",
46 r, r - s3, tm.tm_mday, tm.tm_mon, tm.tm_year);
47 result |= (r == NULL || r - s3 != 17 || tm.tm_mday != 25 || tm.tm_mon != 5
48 || tm.tm_year != 108);
50 return result;
53 #define TEST_FUNCTION do_test ()
54 #include "../test-skeleton.c"