]>
Commit | Line | Data |
---|---|---|
0f585390 | 1 | #include <assert.h> |
04ba8790 UD |
2 | #include <mcheck.h> |
3 | #include <nl_types.h> | |
4 | #include <stdio.h> | |
0f585390 | 5 | #include <stdlib.h> |
04ba8790 | 6 | #include <string.h> |
0f585390 | 7 | #include <sys/resource.h> |
04ba8790 UD |
8 | |
9 | ||
10 | static const char *msgs[] = | |
11 | { | |
12 | #define INPUT(str) | |
13 | #define OUTPUT(str) str, | |
14 | #include <intl/msgs.h> | |
15 | }; | |
16 | #define nmsgs (sizeof (msgs) / sizeof (msgs[0])) | |
17 | ||
0f585390 PP |
18 | |
19 | /* Test for unbounded alloca. */ | |
20 | static int | |
21 | do_bz17905 (void) | |
22 | { | |
23 | char *buf; | |
24 | struct rlimit rl; | |
b4f518ec | 25 | nl_catd result __attribute__ ((unused)); |
0f585390 PP |
26 | |
27 | const int sz = 1024 * 1024; | |
28 | ||
29 | getrlimit (RLIMIT_STACK, &rl); | |
30 | rl.rlim_cur = sz; | |
31 | setrlimit (RLIMIT_STACK, &rl); | |
32 | ||
7565d2a8 | 33 | buf = malloc (sz + 1); |
0f585390 PP |
34 | memset (buf, 'A', sz); |
35 | buf[sz] = '\0'; | |
36 | setenv ("NLSPATH", buf, 1); | |
37 | ||
38 | result = catopen (buf, NL_CAT_LOCALE); | |
39 | assert (result == (nl_catd) -1); | |
40 | ||
41 | free (buf); | |
42 | return 0; | |
43 | } | |
44 | ||
04ba8790 UD |
45 | #define ROUNDS 5 |
46 | ||
29955b5d AS |
47 | static int |
48 | do_test (void) | |
04ba8790 UD |
49 | { |
50 | int rnd; | |
51 | int result = 0; | |
52 | ||
53 | mtrace (); | |
54 | ||
55 | /* We do this a few times to stress the memory handling. */ | |
56 | for (rnd = 0; rnd < ROUNDS; ++rnd) | |
57 | { | |
58 | nl_catd cd = catopen ("libc", 0); | |
57b36a0a | 59 | size_t cnt; |
04ba8790 UD |
60 | |
61 | if (cd == (nl_catd) -1) | |
62 | { | |
63 | printf ("cannot load catalog: %m\n"); | |
64 | result = 1; | |
65 | break; | |
66 | } | |
67 | ||
68 | /* Go through all the messages and compare the result. */ | |
69 | for (cnt = 0; cnt < nmsgs; ++cnt) | |
70 | { | |
71 | char *trans; | |
72 | ||
73 | trans = catgets (cd, 1, 1 + cnt, | |
d747a0a5 | 74 | "+#+# if this comes backs it's an error"); |
04ba8790 UD |
75 | |
76 | if (trans == NULL) | |
77 | { | |
9a2d7205 | 78 | printf ("catgets return NULL for %zd\n", cnt); |
04ba8790 UD |
79 | result = 1; |
80 | } | |
d747a0a5 | 81 | else if (strcmp (trans, msgs[cnt]) != 0 && msgs[cnt][0] != '\0') |
04ba8790 UD |
82 | { |
83 | printf ("expected \"%s\", got \"%s\"\n", msgs[cnt], trans); | |
84 | result = 1; | |
85 | } | |
86 | } | |
87 | ||
88 | if (catclose (cd) != 0) | |
89 | { | |
90 | printf ("catclose failed: %m\n"); | |
91 | result = 1; | |
92 | } | |
93 | } | |
94 | ||
0f585390 | 95 | result += do_bz17905 (); |
04ba8790 UD |
96 | return result; |
97 | } | |
29955b5d AS |
98 | |
99 | #define TEST_FUNCTION do_test () | |
100 | #include "../test-skeleton.c" |