1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at http://curl.haxx.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  ***************************************************************************/
22 
23 /*
24  * The purpose of this test is to minimally exercise libcurl's internal
25  * curl_m*printf formatting capabilities and handling of some data types.
26  */
27 
28 #include "test.h"
29 #include "memdebug.h"
30 
31 
32 #if (CURL_SIZEOF_CURL_OFF_T > CURL_SIZEOF_LONG)
33 #  define MPRNT_SUFFIX_CURL_OFF_T  LL
34 #else
35 #  define MPRNT_SUFFIX_CURL_OFF_T  L
36 #endif
37 
38 
39 #ifdef CURL_ISOCPP
40 #  define MPRNT_OFF_T_C_HELPER2(Val,Suffix) Val ## Suffix
41 #else
42 #  define MPRNT_OFF_T_C_HELPER2(Val,Suffix) Val/**/Suffix
43 #endif
44 #define MPRNT_OFF_T_C_HELPER1(Val,Suffix) MPRNT_OFF_T_C_HELPER2(Val,Suffix)
45 #define MPRNT_OFF_T_C(Val)  MPRNT_OFF_T_C_HELPER1(Val,MPRNT_SUFFIX_CURL_OFF_T)
46 
47 
48 #define BUFSZ    256
49 #define USHORT_TESTS_ARRSZ 1 + 100
50 #define SSHORT_TESTS_ARRSZ 1 + 100
51 #define UINT_TESTS_ARRSZ   1 + 100
52 #define SINT_TESTS_ARRSZ   1 + 100
53 #define ULONG_TESTS_ARRSZ  1 + 100
54 #define SLONG_TESTS_ARRSZ  1 + 100
55 #define COFFT_TESTS_ARRSZ  1 + 100
56 
57 
58 struct unsshort_st {
59   unsigned short num;   /* unsigned short  */
60   const char *expected; /* expected string */
61   char result[BUFSZ];   /* result string   */
62 };
63 
64 
65 struct sigshort_st {
66   short num;            /* signed short    */
67   const char *expected; /* expected string */
68   char result[BUFSZ];   /* result string   */
69 };
70 
71 
72 struct unsint_st {
73   unsigned int num;     /* unsigned int    */
74   const char *expected; /* expected string */
75   char result[BUFSZ];   /* result string   */
76 };
77 
78 
79 struct sigint_st {
80   int num;              /* signed int      */
81   const char *expected; /* expected string */
82   char result[BUFSZ];   /* result string   */
83 };
84 
85 
86 struct unslong_st {
87   unsigned long num;    /* unsigned long   */
88   const char *expected; /* expected string */
89   char result[BUFSZ];   /* result string   */
90 };
91 
92 
93 struct siglong_st {
94   long num;             /* signed long     */
95   const char *expected; /* expected string */
96   char result[BUFSZ];   /* result string   */
97 };
98 
99 
100 struct curloff_st {
101   curl_off_t num;       /* curl_off_t      */
102   const char *expected; /* expected string */
103   char result[BUFSZ];   /* result string   */
104 };
105 
106 
107 static struct unsshort_st us_test[USHORT_TESTS_ARRSZ];
108 static struct sigshort_st ss_test[SSHORT_TESTS_ARRSZ];
109 static struct unsint_st   ui_test[UINT_TESTS_ARRSZ];
110 static struct sigint_st   si_test[SINT_TESTS_ARRSZ];
111 static struct unslong_st  ul_test[ULONG_TESTS_ARRSZ];
112 static struct siglong_st  sl_test[SLONG_TESTS_ARRSZ];
113 static struct curloff_st  co_test[COFFT_TESTS_ARRSZ];
114 
115 
test_unsigned_short_formatting(void)116 static int test_unsigned_short_formatting(void)
117 {
118   int i, j;
119   int num_ushort_tests;
120   int failed = 0;
121 
122 #if (SIZEOF_SHORT == 1)
123 
124   i=1; us_test[i].num = 0xFFU; us_test[i].expected = "256";
125   i++; us_test[i].num = 0xF0U; us_test[i].expected = "240";
126   i++; us_test[i].num = 0x0FU; us_test[i].expected = "15";
127 
128   i++; us_test[i].num = 0xE0U; us_test[i].expected = "224";
129   i++; us_test[i].num = 0x0EU; us_test[i].expected = "14";
130 
131   i++; us_test[i].num = 0xC0U; us_test[i].expected = "192";
132   i++; us_test[i].num = 0x0CU; us_test[i].expected = "12";
133 
134   i++; us_test[i].num = 0x01U; us_test[i].expected = "1";
135   i++; us_test[i].num = 0x00U; us_test[i].expected = "0";
136 
137   num_ushort_tests = i;
138 
139 #elif (SIZEOF_SHORT == 2)
140 
141   i=1; us_test[i].num = 0xFFFFU; us_test[i].expected = "65535";
142   i++; us_test[i].num = 0xFF00U; us_test[i].expected = "65280";
143   i++; us_test[i].num = 0x00FFU; us_test[i].expected = "255";
144 
145   i++; us_test[i].num = 0xF000U; us_test[i].expected = "61440";
146   i++; us_test[i].num = 0x0F00U; us_test[i].expected = "3840";
147   i++; us_test[i].num = 0x00F0U; us_test[i].expected = "240";
148   i++; us_test[i].num = 0x000FU; us_test[i].expected = "15";
149 
150   i++; us_test[i].num = 0xC000U; us_test[i].expected = "49152";
151   i++; us_test[i].num = 0x0C00U; us_test[i].expected = "3072";
152   i++; us_test[i].num = 0x00C0U; us_test[i].expected = "192";
153   i++; us_test[i].num = 0x000CU; us_test[i].expected = "12";
154 
155   i++; us_test[i].num = 0x0001U; us_test[i].expected = "1";
156   i++; us_test[i].num = 0x0000U; us_test[i].expected = "0";
157 
158   num_ushort_tests = i;
159 
160 #elif (SIZEOF_SHORT == 4)
161 
162   i=1; us_test[i].num = 0xFFFFFFFFU; us_test[i].expected = "4294967295";
163   i++; us_test[i].num = 0xFFFF0000U; us_test[i].expected = "4294901760";
164   i++; us_test[i].num = 0x0000FFFFU; us_test[i].expected = "65535";
165 
166   i++; us_test[i].num = 0xFF000000U; us_test[i].expected = "4278190080";
167   i++; us_test[i].num = 0x00FF0000U; us_test[i].expected = "16711680";
168   i++; us_test[i].num = 0x0000FF00U; us_test[i].expected = "65280";
169   i++; us_test[i].num = 0x000000FFU; us_test[i].expected = "255";
170 
171   i++; us_test[i].num = 0xF0000000U; us_test[i].expected = "4026531840";
172   i++; us_test[i].num = 0x0F000000U; us_test[i].expected = "251658240";
173   i++; us_test[i].num = 0x00F00000U; us_test[i].expected = "15728640";
174   i++; us_test[i].num = 0x000F0000U; us_test[i].expected = "983040";
175   i++; us_test[i].num = 0x0000F000U; us_test[i].expected = "61440";
176   i++; us_test[i].num = 0x00000F00U; us_test[i].expected = "3840";
177   i++; us_test[i].num = 0x000000F0U; us_test[i].expected = "240";
178   i++; us_test[i].num = 0x0000000FU; us_test[i].expected = "15";
179 
180   i++; us_test[i].num = 0xC0000000U; us_test[i].expected = "3221225472";
181   i++; us_test[i].num = 0x0C000000U; us_test[i].expected = "201326592";
182   i++; us_test[i].num = 0x00C00000U; us_test[i].expected = "12582912";
183   i++; us_test[i].num = 0x000C0000U; us_test[i].expected = "786432";
184   i++; us_test[i].num = 0x0000C000U; us_test[i].expected = "49152";
185   i++; us_test[i].num = 0x00000C00U; us_test[i].expected = "3072";
186   i++; us_test[i].num = 0x000000C0U; us_test[i].expected = "192";
187   i++; us_test[i].num = 0x0000000CU; us_test[i].expected = "12";
188 
189   i++; us_test[i].num = 0x00000001U; us_test[i].expected = "1";
190   i++; us_test[i].num = 0x00000000U; us_test[i].expected = "0";
191 
192   num_ushort_tests = i;
193 
194 #endif
195 
196   for(i=1; i<=num_ushort_tests; i++) {
197 
198     for(j=0; j<BUFSZ; j++)
199       us_test[i].result[j] = 'X';
200     us_test[i].result[BUFSZ-1] = '\0';
201 
202     (void)curl_msprintf(us_test[i].result, "%hu", us_test[i].num);
203 
204     if(memcmp(us_test[i].result,
205                us_test[i].expected,
206                strlen(us_test[i].expected))) {
207       printf("unsigned short test #%.2d: Failed (Expected: %s Got: %s)\n",
208              i, us_test[i].expected, us_test[i].result);
209       failed++;
210     }
211 
212   }
213 
214   if(!failed)
215     printf("All curl_mprintf() unsigned short tests OK!\n");
216   else
217     printf("Some curl_mprintf() unsigned short tests Failed!\n");
218 
219   return failed;
220 }
221 
222 
test_signed_short_formatting(void)223 static int test_signed_short_formatting(void)
224 {
225   int i, j;
226   int num_sshort_tests;
227   int failed = 0;
228 
229 #if (SIZEOF_SHORT == 1)
230 
231   i=1; ss_test[i].num = 0x7F; ss_test[i].expected = "127";
232 
233   i++; ss_test[i].num = 0x70; ss_test[i].expected = "112";
234   i++; ss_test[i].num = 0x07; ss_test[i].expected = "7";
235 
236   i++; ss_test[i].num = 0x50; ss_test[i].expected = "80";
237   i++; ss_test[i].num = 0x05; ss_test[i].expected = "5";
238 
239   i++; ss_test[i].num = 0x01; ss_test[i].expected = "1";
240   i++; ss_test[i].num = 0x00; ss_test[i].expected = "0";
241 
242   i++; ss_test[i].num = -0x7F -1; ss_test[i].expected = "-128";
243 
244   i++; ss_test[i].num = -0x70 -1; ss_test[i].expected = "-113";
245   i++; ss_test[i].num = -0x07 -1; ss_test[i].expected = "-8";
246 
247   i++; ss_test[i].num = -0x50 -1; ss_test[i].expected = "-81";
248   i++; ss_test[i].num = -0x05 -1; ss_test[i].expected = "-6";
249 
250   i++; ss_test[i].num =  0x00 -1; ss_test[i].expected = "-1";
251 
252   num_sshort_tests = i;
253 
254 #elif (SIZEOF_SHORT == 2)
255 
256   i=1; ss_test[i].num = 0x7FFF; ss_test[i].expected = "32767";
257   i++; ss_test[i].num = 0x7FFE; ss_test[i].expected = "32766";
258   i++; ss_test[i].num = 0x7FFD; ss_test[i].expected = "32765";
259   i++; ss_test[i].num = 0x7F00; ss_test[i].expected = "32512";
260   i++; ss_test[i].num = 0x07F0; ss_test[i].expected = "2032";
261   i++; ss_test[i].num = 0x007F; ss_test[i].expected = "127";
262 
263   i++; ss_test[i].num = 0x7000; ss_test[i].expected = "28672";
264   i++; ss_test[i].num = 0x0700; ss_test[i].expected = "1792";
265   i++; ss_test[i].num = 0x0070; ss_test[i].expected = "112";
266   i++; ss_test[i].num = 0x0007; ss_test[i].expected = "7";
267 
268   i++; ss_test[i].num = 0x5000; ss_test[i].expected = "20480";
269   i++; ss_test[i].num = 0x0500; ss_test[i].expected = "1280";
270   i++; ss_test[i].num = 0x0050; ss_test[i].expected = "80";
271   i++; ss_test[i].num = 0x0005; ss_test[i].expected = "5";
272 
273   i++; ss_test[i].num = 0x0001; ss_test[i].expected = "1";
274   i++; ss_test[i].num = 0x0000; ss_test[i].expected = "0";
275 
276   i++; ss_test[i].num = -0x7FFF -1; ss_test[i].expected = "-32768";
277   i++; ss_test[i].num = -0x7FFE -1; ss_test[i].expected = "-32767";
278   i++; ss_test[i].num = -0x7FFD -1; ss_test[i].expected = "-32766";
279   i++; ss_test[i].num = -0x7F00 -1; ss_test[i].expected = "-32513";
280   i++; ss_test[i].num = -0x07F0 -1; ss_test[i].expected = "-2033";
281   i++; ss_test[i].num = -0x007F -1; ss_test[i].expected = "-128";
282 
283   i++; ss_test[i].num = -0x7000 -1; ss_test[i].expected = "-28673";
284   i++; ss_test[i].num = -0x0700 -1; ss_test[i].expected = "-1793";
285   i++; ss_test[i].num = -0x0070 -1; ss_test[i].expected = "-113";
286   i++; ss_test[i].num = -0x0007 -1; ss_test[i].expected = "-8";
287 
288   i++; ss_test[i].num = -0x5000 -1; ss_test[i].expected = "-20481";
289   i++; ss_test[i].num = -0x0500 -1; ss_test[i].expected = "-1281";
290   i++; ss_test[i].num = -0x0050 -1; ss_test[i].expected = "-81";
291   i++; ss_test[i].num = -0x0005 -1; ss_test[i].expected = "-6";
292 
293   i++; ss_test[i].num =  0x0000 -1; ss_test[i].expected = "-1";
294 
295   num_sshort_tests = i;
296 
297 #elif (SIZEOF_SHORT == 4)
298 
299   i=1; ss_test[i].num = 0x7FFFFFFF; ss_test[i].expected = "2147483647";
300   i++; ss_test[i].num = 0x7FFFFFFE; ss_test[i].expected = "2147483646";
301   i++; ss_test[i].num = 0x7FFFFFFD; ss_test[i].expected = "2147483645";
302   i++; ss_test[i].num = 0x7FFF0000; ss_test[i].expected = "2147418112";
303   i++; ss_test[i].num = 0x00007FFF; ss_test[i].expected = "32767";
304 
305   i++; ss_test[i].num = 0x7F000000; ss_test[i].expected = "2130706432";
306   i++; ss_test[i].num = 0x007F0000; ss_test[i].expected = "8323072";
307   i++; ss_test[i].num = 0x00007F00; ss_test[i].expected = "32512";
308   i++; ss_test[i].num = 0x0000007F; ss_test[i].expected = "127";
309 
310   i++; ss_test[i].num = 0x70000000; ss_test[i].expected = "1879048192";
311   i++; ss_test[i].num = 0x07000000; ss_test[i].expected = "117440512";
312   i++; ss_test[i].num = 0x00700000; ss_test[i].expected = "7340032";
313   i++; ss_test[i].num = 0x00070000; ss_test[i].expected = "458752";
314   i++; ss_test[i].num = 0x00007000; ss_test[i].expected = "28672";
315   i++; ss_test[i].num = 0x00000700; ss_test[i].expected = "1792";
316   i++; ss_test[i].num = 0x00000070; ss_test[i].expected = "112";
317   i++; ss_test[i].num = 0x00000007; ss_test[i].expected = "7";
318 
319   i++; ss_test[i].num = 0x50000000; ss_test[i].expected = "1342177280";
320   i++; ss_test[i].num = 0x05000000; ss_test[i].expected = "83886080";
321   i++; ss_test[i].num = 0x00500000; ss_test[i].expected = "5242880";
322   i++; ss_test[i].num = 0x00050000; ss_test[i].expected = "327680";
323   i++; ss_test[i].num = 0x00005000; ss_test[i].expected = "20480";
324   i++; ss_test[i].num = 0x00000500; ss_test[i].expected = "1280";
325   i++; ss_test[i].num = 0x00000050; ss_test[i].expected = "80";
326   i++; ss_test[i].num = 0x00000005; ss_test[i].expected = "5";
327 
328   i++; ss_test[i].num = 0x00000001; ss_test[i].expected = "1";
329   i++; ss_test[i].num = 0x00000000; ss_test[i].expected = "0";
330 
331   i++; ss_test[i].num = -0x7FFFFFFF -1; ss_test[i].expected = "-2147483648";
332   i++; ss_test[i].num = -0x7FFFFFFE -1; ss_test[i].expected = "-2147483647";
333   i++; ss_test[i].num = -0x7FFFFFFD -1; ss_test[i].expected = "-2147483646";
334   i++; ss_test[i].num = -0x7FFF0000 -1; ss_test[i].expected = "-2147418113";
335   i++; ss_test[i].num = -0x00007FFF -1; ss_test[i].expected = "-32768";
336 
337   i++; ss_test[i].num = -0x7F000000 -1; ss_test[i].expected = "-2130706433";
338   i++; ss_test[i].num = -0x007F0000 -1; ss_test[i].expected = "-8323073";
339   i++; ss_test[i].num = -0x00007F00 -1; ss_test[i].expected = "-32513";
340   i++; ss_test[i].num = -0x0000007F -1; ss_test[i].expected = "-128";
341 
342   i++; ss_test[i].num = -0x70000000 -1; ss_test[i].expected = "-1879048193";
343   i++; ss_test[i].num = -0x07000000 -1; ss_test[i].expected = "-117440513";
344   i++; ss_test[i].num = -0x00700000 -1; ss_test[i].expected = "-7340033";
345   i++; ss_test[i].num = -0x00070000 -1; ss_test[i].expected = "-458753";
346   i++; ss_test[i].num = -0x00007000 -1; ss_test[i].expected = "-28673";
347   i++; ss_test[i].num = -0x00000700 -1; ss_test[i].expected = "-1793";
348   i++; ss_test[i].num = -0x00000070 -1; ss_test[i].expected = "-113";
349   i++; ss_test[i].num = -0x00000007 -1; ss_test[i].expected = "-8";
350 
351   i++; ss_test[i].num = -0x50000000 -1; ss_test[i].expected = "-1342177281";
352   i++; ss_test[i].num = -0x05000000 -1; ss_test[i].expected = "-83886081";
353   i++; ss_test[i].num = -0x00500000 -1; ss_test[i].expected = "-5242881";
354   i++; ss_test[i].num = -0x00050000 -1; ss_test[i].expected = "-327681";
355   i++; ss_test[i].num = -0x00005000 -1; ss_test[i].expected = "-20481";
356   i++; ss_test[i].num = -0x00000500 -1; ss_test[i].expected = "-1281";
357   i++; ss_test[i].num = -0x00000050 -1; ss_test[i].expected = "-81";
358   i++; ss_test[i].num = -0x00000005 -1; ss_test[i].expected = "-6";
359 
360   i++; ss_test[i].num =  0x00000000 -1; ss_test[i].expected = "-1";
361 
362   num_sshort_tests = i;
363 
364 #endif
365 
366   for(i=1; i<=num_sshort_tests; i++) {
367 
368     for(j=0; j<BUFSZ; j++)
369       ss_test[i].result[j] = 'X';
370     ss_test[i].result[BUFSZ-1] = '\0';
371 
372     (void)curl_msprintf(ss_test[i].result, "%hd", ss_test[i].num);
373 
374     if(memcmp(ss_test[i].result,
375               ss_test[i].expected,
376               strlen(ss_test[i].expected))) {
377       printf("signed short test #%.2d: Failed (Expected: %s Got: %s)\n",
378              i, ss_test[i].expected, ss_test[i].result);
379       failed++;
380     }
381 
382   }
383 
384   if(!failed)
385     printf("All curl_mprintf() signed short tests OK!\n");
386   else
387     printf("Some curl_mprintf() signed short tests Failed!\n");
388 
389   return failed;
390 }
391 
392 
test_unsigned_int_formatting(void)393 static int test_unsigned_int_formatting(void)
394 {
395   int i, j;
396   int num_uint_tests;
397   int failed = 0;
398 
399 #if (SIZEOF_INT == 2)
400 
401   i=1; ui_test[i].num = 0xFFFFU; ui_test[i].expected = "65535";
402   i++; ui_test[i].num = 0xFF00U; ui_test[i].expected = "65280";
403   i++; ui_test[i].num = 0x00FFU; ui_test[i].expected = "255";
404 
405   i++; ui_test[i].num = 0xF000U; ui_test[i].expected = "61440";
406   i++; ui_test[i].num = 0x0F00U; ui_test[i].expected = "3840";
407   i++; ui_test[i].num = 0x00F0U; ui_test[i].expected = "240";
408   i++; ui_test[i].num = 0x000FU; ui_test[i].expected = "15";
409 
410   i++; ui_test[i].num = 0xC000U; ui_test[i].expected = "49152";
411   i++; ui_test[i].num = 0x0C00U; ui_test[i].expected = "3072";
412   i++; ui_test[i].num = 0x00C0U; ui_test[i].expected = "192";
413   i++; ui_test[i].num = 0x000CU; ui_test[i].expected = "12";
414 
415   i++; ui_test[i].num = 0x0001U; ui_test[i].expected = "1";
416   i++; ui_test[i].num = 0x0000U; ui_test[i].expected = "0";
417 
418   num_uint_tests = i;
419 
420 #elif (SIZEOF_INT == 4)
421 
422   i=1; ui_test[i].num = 0xFFFFFFFFU; ui_test[i].expected = "4294967295";
423   i++; ui_test[i].num = 0xFFFF0000U; ui_test[i].expected = "4294901760";
424   i++; ui_test[i].num = 0x0000FFFFU; ui_test[i].expected = "65535";
425 
426   i++; ui_test[i].num = 0xFF000000U; ui_test[i].expected = "4278190080";
427   i++; ui_test[i].num = 0x00FF0000U; ui_test[i].expected = "16711680";
428   i++; ui_test[i].num = 0x0000FF00U; ui_test[i].expected = "65280";
429   i++; ui_test[i].num = 0x000000FFU; ui_test[i].expected = "255";
430 
431   i++; ui_test[i].num = 0xF0000000U; ui_test[i].expected = "4026531840";
432   i++; ui_test[i].num = 0x0F000000U; ui_test[i].expected = "251658240";
433   i++; ui_test[i].num = 0x00F00000U; ui_test[i].expected = "15728640";
434   i++; ui_test[i].num = 0x000F0000U; ui_test[i].expected = "983040";
435   i++; ui_test[i].num = 0x0000F000U; ui_test[i].expected = "61440";
436   i++; ui_test[i].num = 0x00000F00U; ui_test[i].expected = "3840";
437   i++; ui_test[i].num = 0x000000F0U; ui_test[i].expected = "240";
438   i++; ui_test[i].num = 0x0000000FU; ui_test[i].expected = "15";
439 
440   i++; ui_test[i].num = 0xC0000000U; ui_test[i].expected = "3221225472";
441   i++; ui_test[i].num = 0x0C000000U; ui_test[i].expected = "201326592";
442   i++; ui_test[i].num = 0x00C00000U; ui_test[i].expected = "12582912";
443   i++; ui_test[i].num = 0x000C0000U; ui_test[i].expected = "786432";
444   i++; ui_test[i].num = 0x0000C000U; ui_test[i].expected = "49152";
445   i++; ui_test[i].num = 0x00000C00U; ui_test[i].expected = "3072";
446   i++; ui_test[i].num = 0x000000C0U; ui_test[i].expected = "192";
447   i++; ui_test[i].num = 0x0000000CU; ui_test[i].expected = "12";
448 
449   i++; ui_test[i].num = 0x00000001U; ui_test[i].expected = "1";
450   i++; ui_test[i].num = 0x00000000U; ui_test[i].expected = "0";
451 
452   num_uint_tests = i;
453 
454 #elif (SIZEOF_INT == 8)
455 
456   i=1; ui_test[i].num = 0xFFFFFFFFFFFFFFFFU; ui_test[i].expected = "18446744073709551615";
457   i++; ui_test[i].num = 0xFFFFFFFF00000000U; ui_test[i].expected = "18446744069414584320";
458   i++; ui_test[i].num = 0x00000000FFFFFFFFU; ui_test[i].expected = "4294967295";
459 
460   i++; ui_test[i].num = 0xFFFF000000000000U; ui_test[i].expected = "18446462598732840960";
461   i++; ui_test[i].num = 0x0000FFFF00000000U; ui_test[i].expected = "281470681743360";
462   i++; ui_test[i].num = 0x00000000FFFF0000U; ui_test[i].expected = "4294901760";
463   i++; ui_test[i].num = 0x000000000000FFFFU; ui_test[i].expected = "65535";
464 
465   i++; ui_test[i].num = 0xFF00000000000000U; ui_test[i].expected = "18374686479671623680";
466   i++; ui_test[i].num = 0x00FF000000000000U; ui_test[i].expected = "71776119061217280";
467   i++; ui_test[i].num = 0x0000FF0000000000U; ui_test[i].expected = "280375465082880";
468   i++; ui_test[i].num = 0x000000FF00000000U; ui_test[i].expected = "1095216660480";
469   i++; ui_test[i].num = 0x00000000FF000000U; ui_test[i].expected = "4278190080";
470   i++; ui_test[i].num = 0x0000000000FF0000U; ui_test[i].expected = "16711680";
471   i++; ui_test[i].num = 0x000000000000FF00U; ui_test[i].expected = "65280";
472   i++; ui_test[i].num = 0x00000000000000FFU; ui_test[i].expected = "255";
473 
474   i++; ui_test[i].num = 0xF000000000000000U; ui_test[i].expected = "17293822569102704640";
475   i++; ui_test[i].num = 0x0F00000000000000U; ui_test[i].expected = "1080863910568919040";
476   i++; ui_test[i].num = 0x00F0000000000000U; ui_test[i].expected = "67553994410557440";
477   i++; ui_test[i].num = 0x000F000000000000U; ui_test[i].expected = "4222124650659840";
478   i++; ui_test[i].num = 0x0000F00000000000U; ui_test[i].expected = "263882790666240";
479   i++; ui_test[i].num = 0x00000F0000000000U; ui_test[i].expected = "16492674416640";
480   i++; ui_test[i].num = 0x000000F000000000U; ui_test[i].expected = "1030792151040";
481   i++; ui_test[i].num = 0x0000000F00000000U; ui_test[i].expected = "64424509440";
482   i++; ui_test[i].num = 0x00000000F0000000U; ui_test[i].expected = "4026531840";
483   i++; ui_test[i].num = 0x000000000F000000U; ui_test[i].expected = "251658240";
484   i++; ui_test[i].num = 0x0000000000F00000U; ui_test[i].expected = "15728640";
485   i++; ui_test[i].num = 0x00000000000F0000U; ui_test[i].expected = "983040";
486   i++; ui_test[i].num = 0x000000000000F000U; ui_test[i].expected = "61440";
487   i++; ui_test[i].num = 0x0000000000000F00U; ui_test[i].expected = "3840";
488   i++; ui_test[i].num = 0x00000000000000F0U; ui_test[i].expected = "240";
489   i++; ui_test[i].num = 0x000000000000000FU; ui_test[i].expected = "15";
490 
491   i++; ui_test[i].num = 0xC000000000000000U; ui_test[i].expected = "13835058055282163712";
492   i++; ui_test[i].num = 0x0C00000000000000U; ui_test[i].expected = "864691128455135232";
493   i++; ui_test[i].num = 0x00C0000000000000U; ui_test[i].expected = "54043195528445952";
494   i++; ui_test[i].num = 0x000C000000000000U; ui_test[i].expected = "3377699720527872";
495   i++; ui_test[i].num = 0x0000C00000000000U; ui_test[i].expected = "211106232532992";
496   i++; ui_test[i].num = 0x00000C0000000000U; ui_test[i].expected = "13194139533312";
497   i++; ui_test[i].num = 0x000000C000000000U; ui_test[i].expected = "824633720832";
498   i++; ui_test[i].num = 0x0000000C00000000U; ui_test[i].expected = "51539607552";
499   i++; ui_test[i].num = 0x00000000C0000000U; ui_test[i].expected = "3221225472";
500   i++; ui_test[i].num = 0x000000000C000000U; ui_test[i].expected = "201326592";
501   i++; ui_test[i].num = 0x0000000000C00000U; ui_test[i].expected = "12582912";
502   i++; ui_test[i].num = 0x00000000000C0000U; ui_test[i].expected = "786432";
503   i++; ui_test[i].num = 0x000000000000C000U; ui_test[i].expected = "49152";
504   i++; ui_test[i].num = 0x0000000000000C00U; ui_test[i].expected = "3072";
505   i++; ui_test[i].num = 0x00000000000000C0U; ui_test[i].expected = "192";
506   i++; ui_test[i].num = 0x000000000000000CU; ui_test[i].expected = "12";
507 
508   i++; ui_test[i].num = 0x00000001U; ui_test[i].expected = "1";
509   i++; ui_test[i].num = 0x00000000U; ui_test[i].expected = "0";
510 
511   num_uint_tests = i;
512 
513 #endif
514 
515   for(i=1; i<=num_uint_tests; i++) {
516 
517     for(j=0; j<BUFSZ; j++)
518       ui_test[i].result[j] = 'X';
519     ui_test[i].result[BUFSZ-1] = '\0';
520 
521     (void)curl_msprintf(ui_test[i].result, "%u", ui_test[i].num);
522 
523     if(memcmp(ui_test[i].result,
524                ui_test[i].expected,
525                strlen(ui_test[i].expected))) {
526       printf("unsigned int test #%.2d: Failed (Expected: %s Got: %s)\n",
527              i, ui_test[i].expected, ui_test[i].result);
528       failed++;
529     }
530 
531   }
532 
533   if(!failed)
534     printf("All curl_mprintf() unsigned int tests OK!\n");
535   else
536     printf("Some curl_mprintf() unsigned int tests Failed!\n");
537 
538   return failed;
539 }
540 
541 
test_signed_int_formatting(void)542 static int test_signed_int_formatting(void)
543 {
544   int i, j;
545   int num_sint_tests;
546   int failed = 0;
547 
548 #if (SIZEOF_INT == 2)
549 
550   i=1; si_test[i].num = 0x7FFF; si_test[i].expected = "32767";
551   i++; si_test[i].num = 0x7FFE; si_test[i].expected = "32766";
552   i++; si_test[i].num = 0x7FFD; si_test[i].expected = "32765";
553   i++; si_test[i].num = 0x7F00; si_test[i].expected = "32512";
554   i++; si_test[i].num = 0x07F0; si_test[i].expected = "2032";
555   i++; si_test[i].num = 0x007F; si_test[i].expected = "127";
556 
557   i++; si_test[i].num = 0x7000; si_test[i].expected = "28672";
558   i++; si_test[i].num = 0x0700; si_test[i].expected = "1792";
559   i++; si_test[i].num = 0x0070; si_test[i].expected = "112";
560   i++; si_test[i].num = 0x0007; si_test[i].expected = "7";
561 
562   i++; si_test[i].num = 0x5000; si_test[i].expected = "20480";
563   i++; si_test[i].num = 0x0500; si_test[i].expected = "1280";
564   i++; si_test[i].num = 0x0050; si_test[i].expected = "80";
565   i++; si_test[i].num = 0x0005; si_test[i].expected = "5";
566 
567   i++; si_test[i].num = 0x0001; si_test[i].expected = "1";
568   i++; si_test[i].num = 0x0000; si_test[i].expected = "0";
569 
570   i++; si_test[i].num = -0x7FFF -1; si_test[i].expected = "-32768";
571   i++; si_test[i].num = -0x7FFE -1; si_test[i].expected = "-32767";
572   i++; si_test[i].num = -0x7FFD -1; si_test[i].expected = "-32766";
573   i++; si_test[i].num = -0x7F00 -1; si_test[i].expected = "-32513";
574   i++; si_test[i].num = -0x07F0 -1; si_test[i].expected = "-2033";
575   i++; si_test[i].num = -0x007F -1; si_test[i].expected = "-128";
576 
577   i++; si_test[i].num = -0x7000 -1; si_test[i].expected = "-28673";
578   i++; si_test[i].num = -0x0700 -1; si_test[i].expected = "-1793";
579   i++; si_test[i].num = -0x0070 -1; si_test[i].expected = "-113";
580   i++; si_test[i].num = -0x0007 -1; si_test[i].expected = "-8";
581 
582   i++; si_test[i].num = -0x5000 -1; si_test[i].expected = "-20481";
583   i++; si_test[i].num = -0x0500 -1; si_test[i].expected = "-1281";
584   i++; si_test[i].num = -0x0050 -1; si_test[i].expected = "-81";
585   i++; si_test[i].num = -0x0005 -1; si_test[i].expected = "-6";
586 
587   i++; si_test[i].num =  0x0000 -1; si_test[i].expected = "-1";
588 
589   num_sint_tests = i;
590 
591 #elif (SIZEOF_INT == 4)
592 
593   i=1; si_test[i].num = 0x7FFFFFFF; si_test[i].expected = "2147483647";
594   i++; si_test[i].num = 0x7FFFFFFE; si_test[i].expected = "2147483646";
595   i++; si_test[i].num = 0x7FFFFFFD; si_test[i].expected = "2147483645";
596   i++; si_test[i].num = 0x7FFF0000; si_test[i].expected = "2147418112";
597   i++; si_test[i].num = 0x00007FFF; si_test[i].expected = "32767";
598 
599   i++; si_test[i].num = 0x7F000000; si_test[i].expected = "2130706432";
600   i++; si_test[i].num = 0x007F0000; si_test[i].expected = "8323072";
601   i++; si_test[i].num = 0x00007F00; si_test[i].expected = "32512";
602   i++; si_test[i].num = 0x0000007F; si_test[i].expected = "127";
603 
604   i++; si_test[i].num = 0x70000000; si_test[i].expected = "1879048192";
605   i++; si_test[i].num = 0x07000000; si_test[i].expected = "117440512";
606   i++; si_test[i].num = 0x00700000; si_test[i].expected = "7340032";
607   i++; si_test[i].num = 0x00070000; si_test[i].expected = "458752";
608   i++; si_test[i].num = 0x00007000; si_test[i].expected = "28672";
609   i++; si_test[i].num = 0x00000700; si_test[i].expected = "1792";
610   i++; si_test[i].num = 0x00000070; si_test[i].expected = "112";
611   i++; si_test[i].num = 0x00000007; si_test[i].expected = "7";
612 
613   i++; si_test[i].num = 0x50000000; si_test[i].expected = "1342177280";
614   i++; si_test[i].num = 0x05000000; si_test[i].expected = "83886080";
615   i++; si_test[i].num = 0x00500000; si_test[i].expected = "5242880";
616   i++; si_test[i].num = 0x00050000; si_test[i].expected = "327680";
617   i++; si_test[i].num = 0x00005000; si_test[i].expected = "20480";
618   i++; si_test[i].num = 0x00000500; si_test[i].expected = "1280";
619   i++; si_test[i].num = 0x00000050; si_test[i].expected = "80";
620   i++; si_test[i].num = 0x00000005; si_test[i].expected = "5";
621 
622   i++; si_test[i].num = 0x00000001; si_test[i].expected = "1";
623   i++; si_test[i].num = 0x00000000; si_test[i].expected = "0";
624 
625   i++; si_test[i].num = -0x7FFFFFFF -1; si_test[i].expected = "-2147483648";
626   i++; si_test[i].num = -0x7FFFFFFE -1; si_test[i].expected = "-2147483647";
627   i++; si_test[i].num = -0x7FFFFFFD -1; si_test[i].expected = "-2147483646";
628   i++; si_test[i].num = -0x7FFF0000 -1; si_test[i].expected = "-2147418113";
629   i++; si_test[i].num = -0x00007FFF -1; si_test[i].expected = "-32768";
630 
631   i++; si_test[i].num = -0x7F000000 -1; si_test[i].expected = "-2130706433";
632   i++; si_test[i].num = -0x007F0000 -1; si_test[i].expected = "-8323073";
633   i++; si_test[i].num = -0x00007F00 -1; si_test[i].expected = "-32513";
634   i++; si_test[i].num = -0x0000007F -1; si_test[i].expected = "-128";
635 
636   i++; si_test[i].num = -0x70000000 -1; si_test[i].expected = "-1879048193";
637   i++; si_test[i].num = -0x07000000 -1; si_test[i].expected = "-117440513";
638   i++; si_test[i].num = -0x00700000 -1; si_test[i].expected = "-7340033";
639   i++; si_test[i].num = -0x00070000 -1; si_test[i].expected = "-458753";
640   i++; si_test[i].num = -0x00007000 -1; si_test[i].expected = "-28673";
641   i++; si_test[i].num = -0x00000700 -1; si_test[i].expected = "-1793";
642   i++; si_test[i].num = -0x00000070 -1; si_test[i].expected = "-113";
643   i++; si_test[i].num = -0x00000007 -1; si_test[i].expected = "-8";
644 
645   i++; si_test[i].num = -0x50000000 -1; si_test[i].expected = "-1342177281";
646   i++; si_test[i].num = -0x05000000 -1; si_test[i].expected = "-83886081";
647   i++; si_test[i].num = -0x00500000 -1; si_test[i].expected = "-5242881";
648   i++; si_test[i].num = -0x00050000 -1; si_test[i].expected = "-327681";
649   i++; si_test[i].num = -0x00005000 -1; si_test[i].expected = "-20481";
650   i++; si_test[i].num = -0x00000500 -1; si_test[i].expected = "-1281";
651   i++; si_test[i].num = -0x00000050 -1; si_test[i].expected = "-81";
652   i++; si_test[i].num = -0x00000005 -1; si_test[i].expected = "-6";
653 
654   i++; si_test[i].num =  0x00000000 -1; si_test[i].expected = "-1";
655 
656   num_sint_tests = i;
657 
658 #elif (SIZEOF_INT == 8)
659 
660   i=1; si_test[i].num = 0x7FFFFFFFFFFFFFFF; si_test[i].expected = "9223372036854775807";
661   i++; si_test[i].num = 0x7FFFFFFFFFFFFFFE; si_test[i].expected = "9223372036854775806";
662   i++; si_test[i].num = 0x7FFFFFFFFFFFFFFD; si_test[i].expected = "9223372036854775805";
663   i++; si_test[i].num = 0x7FFFFFFF00000000; si_test[i].expected = "9223372032559808512";
664   i++; si_test[i].num = 0x000000007FFFFFFF; si_test[i].expected = "2147483647";
665 
666   i++; si_test[i].num = 0x7FFF000000000000; si_test[i].expected = "9223090561878065152";
667   i++; si_test[i].num = 0x00007FFF00000000; si_test[i].expected = "140733193388032";
668   i++; si_test[i].num = 0x000000007FFF0000; si_test[i].expected = "2147418112";
669   i++; si_test[i].num = 0x0000000000007FFF; si_test[i].expected = "32767";
670 
671   i++; si_test[i].num = 0x7F00000000000000; si_test[i].expected = "9151314442816847872";
672   i++; si_test[i].num = 0x007F000000000000; si_test[i].expected = "35747322042253312";
673   i++; si_test[i].num = 0x00007F0000000000; si_test[i].expected = "139637976727552";
674   i++; si_test[i].num = 0x0000007F00000000; si_test[i].expected = "545460846592";
675   i++; si_test[i].num = 0x000000007F000000; si_test[i].expected = "2130706432";
676   i++; si_test[i].num = 0x00000000007F0000; si_test[i].expected = "8323072";
677   i++; si_test[i].num = 0x0000000000007F00; si_test[i].expected = "32512";
678   i++; si_test[i].num = 0x000000000000007F; si_test[i].expected = "127";
679 
680   i++; si_test[i].num = 0x7000000000000000; si_test[i].expected = "8070450532247928832";
681   i++; si_test[i].num = 0x0700000000000000; si_test[i].expected = "504403158265495552";
682   i++; si_test[i].num = 0x0070000000000000; si_test[i].expected = "31525197391593472";
683   i++; si_test[i].num = 0x0007000000000000; si_test[i].expected = "1970324836974592";
684   i++; si_test[i].num = 0x0000700000000000; si_test[i].expected = "123145302310912";
685   i++; si_test[i].num = 0x0000070000000000; si_test[i].expected = "7696581394432";
686   i++; si_test[i].num = 0x0000007000000000; si_test[i].expected = "481036337152";
687   i++; si_test[i].num = 0x0000000700000000; si_test[i].expected = "30064771072";
688   i++; si_test[i].num = 0x0000000070000000; si_test[i].expected = "1879048192";
689   i++; si_test[i].num = 0x0000000007000000; si_test[i].expected = "117440512";
690   i++; si_test[i].num = 0x0000000000700000; si_test[i].expected = "7340032";
691   i++; si_test[i].num = 0x0000000000070000; si_test[i].expected = "458752";
692   i++; si_test[i].num = 0x0000000000007000; si_test[i].expected = "28672";
693   i++; si_test[i].num = 0x0000000000000700; si_test[i].expected = "1792";
694   i++; si_test[i].num = 0x0000000000000070; si_test[i].expected = "112";
695   i++; si_test[i].num = 0x0000000000000007; si_test[i].expected = "7";
696 
697   i++; si_test[i].num = 0x0000000000000001; si_test[i].expected = "1";
698   i++; si_test[i].num = 0x0000000000000000; si_test[i].expected = "0";
699 
700   i++; si_test[i].num = -0x7FFFFFFFFFFFFFFF -1; si_test[i].expected = "-9223372036854775808";
701   i++; si_test[i].num = -0x7FFFFFFFFFFFFFFE -1; si_test[i].expected = "-9223372036854775807";
702   i++; si_test[i].num = -0x7FFFFFFFFFFFFFFD -1; si_test[i].expected = "-9223372036854775806";
703   i++; si_test[i].num = -0x7FFFFFFF00000000 -1; si_test[i].expected = "-9223372032559808513";
704   i++; si_test[i].num = -0x000000007FFFFFFF -1; si_test[i].expected = "-2147483648";
705 
706   i++; si_test[i].num = -0x7FFF000000000000 -1; si_test[i].expected = "-9223090561878065153";
707   i++; si_test[i].num = -0x00007FFF00000000 -1; si_test[i].expected = "-140733193388033";
708   i++; si_test[i].num = -0x000000007FFF0000 -1; si_test[i].expected = "-2147418113";
709   i++; si_test[i].num = -0x0000000000007FFF -1; si_test[i].expected = "-32768";
710 
711   i++; si_test[i].num = -0x7F00000000000000 -1; si_test[i].expected = "-9151314442816847873";
712   i++; si_test[i].num = -0x007F000000000000 -1; si_test[i].expected = "-35747322042253313";
713   i++; si_test[i].num = -0x00007F0000000000 -1; si_test[i].expected = "-139637976727553";
714   i++; si_test[i].num = -0x0000007F00000000 -1; si_test[i].expected = "-545460846593";
715   i++; si_test[i].num = -0x000000007F000000 -1; si_test[i].expected = "-2130706433";
716   i++; si_test[i].num = -0x00000000007F0000 -1; si_test[i].expected = "-8323073";
717   i++; si_test[i].num = -0x0000000000007F00 -1; si_test[i].expected = "-32513";
718   i++; si_test[i].num = -0x000000000000007F -1; si_test[i].expected = "-128";
719 
720   i++; si_test[i].num = -0x7000000000000000 -1; si_test[i].expected = "-8070450532247928833";
721   i++; si_test[i].num = -0x0700000000000000 -1; si_test[i].expected = "-504403158265495553";
722   i++; si_test[i].num = -0x0070000000000000 -1; si_test[i].expected = "-31525197391593473";
723   i++; si_test[i].num = -0x0007000000000000 -1; si_test[i].expected = "-1970324836974593";
724   i++; si_test[i].num = -0x0000700000000000 -1; si_test[i].expected = "-123145302310913";
725   i++; si_test[i].num = -0x0000070000000000 -1; si_test[i].expected = "-7696581394433";
726   i++; si_test[i].num = -0x0000007000000000 -1; si_test[i].expected = "-481036337153";
727   i++; si_test[i].num = -0x0000000700000000 -1; si_test[i].expected = "-30064771073";
728   i++; si_test[i].num = -0x0000000070000000 -1; si_test[i].expected = "-1879048193";
729   i++; si_test[i].num = -0x0000000007000000 -1; si_test[i].expected = "-117440513";
730   i++; si_test[i].num = -0x0000000000700000 -1; si_test[i].expected = "-7340033";
731   i++; si_test[i].num = -0x0000000000070000 -1; si_test[i].expected = "-458753";
732   i++; si_test[i].num = -0x0000000000007000 -1; si_test[i].expected = "-28673";
733   i++; si_test[i].num = -0x0000000000000700 -1; si_test[i].expected = "-1793";
734   i++; si_test[i].num = -0x0000000000000070 -1; si_test[i].expected = "-113";
735   i++; si_test[i].num = -0x0000000000000007 -1; si_test[i].expected = "-8";
736 
737   i++; si_test[i].num =  0x0000000000000000 -1; si_test[i].expected = "-1";
738 
739   num_sint_tests = i;
740 
741 #endif
742 
743   for(i=1; i<=num_sint_tests; i++) {
744 
745     for(j=0; j<BUFSZ; j++)
746       si_test[i].result[j] = 'X';
747     si_test[i].result[BUFSZ-1] = '\0';
748 
749     (void)curl_msprintf(si_test[i].result, "%d", si_test[i].num);
750 
751     if(memcmp(si_test[i].result,
752               si_test[i].expected,
753               strlen(si_test[i].expected))) {
754       printf("signed int test #%.2d: Failed (Expected: %s Got: %s)\n",
755              i, si_test[i].expected, si_test[i].result);
756       failed++;
757     }
758 
759   }
760 
761   if(!failed)
762     printf("All curl_mprintf() signed int tests OK!\n");
763   else
764     printf("Some curl_mprintf() signed int tests Failed!\n");
765 
766   return failed;
767 }
768 
769 
test_unsigned_long_formatting(void)770 static int test_unsigned_long_formatting(void)
771 {
772   int i, j;
773   int num_ulong_tests;
774   int failed = 0;
775 
776 #if (CURL_SIZEOF_LONG == 2)
777 
778   i=1; ul_test[i].num = 0xFFFFUL; ul_test[i].expected = "65535";
779   i++; ul_test[i].num = 0xFF00UL; ul_test[i].expected = "65280";
780   i++; ul_test[i].num = 0x00FFUL; ul_test[i].expected = "255";
781 
782   i++; ul_test[i].num = 0xF000UL; ul_test[i].expected = "61440";
783   i++; ul_test[i].num = 0x0F00UL; ul_test[i].expected = "3840";
784   i++; ul_test[i].num = 0x00F0UL; ul_test[i].expected = "240";
785   i++; ul_test[i].num = 0x000FUL; ul_test[i].expected = "15";
786 
787   i++; ul_test[i].num = 0xC000UL; ul_test[i].expected = "49152";
788   i++; ul_test[i].num = 0x0C00UL; ul_test[i].expected = "3072";
789   i++; ul_test[i].num = 0x00C0UL; ul_test[i].expected = "192";
790   i++; ul_test[i].num = 0x000CUL; ul_test[i].expected = "12";
791 
792   i++; ul_test[i].num = 0x0001UL; ul_test[i].expected = "1";
793   i++; ul_test[i].num = 0x0000UL; ul_test[i].expected = "0";
794 
795   num_ulong_tests = i;
796 
797 #elif (CURL_SIZEOF_LONG == 4)
798 
799   i=1; ul_test[i].num = 0xFFFFFFFFUL; ul_test[i].expected = "4294967295";
800   i++; ul_test[i].num = 0xFFFF0000UL; ul_test[i].expected = "4294901760";
801   i++; ul_test[i].num = 0x0000FFFFUL; ul_test[i].expected = "65535";
802 
803   i++; ul_test[i].num = 0xFF000000UL; ul_test[i].expected = "4278190080";
804   i++; ul_test[i].num = 0x00FF0000UL; ul_test[i].expected = "16711680";
805   i++; ul_test[i].num = 0x0000FF00UL; ul_test[i].expected = "65280";
806   i++; ul_test[i].num = 0x000000FFUL; ul_test[i].expected = "255";
807 
808   i++; ul_test[i].num = 0xF0000000UL; ul_test[i].expected = "4026531840";
809   i++; ul_test[i].num = 0x0F000000UL; ul_test[i].expected = "251658240";
810   i++; ul_test[i].num = 0x00F00000UL; ul_test[i].expected = "15728640";
811   i++; ul_test[i].num = 0x000F0000UL; ul_test[i].expected = "983040";
812   i++; ul_test[i].num = 0x0000F000UL; ul_test[i].expected = "61440";
813   i++; ul_test[i].num = 0x00000F00UL; ul_test[i].expected = "3840";
814   i++; ul_test[i].num = 0x000000F0UL; ul_test[i].expected = "240";
815   i++; ul_test[i].num = 0x0000000FUL; ul_test[i].expected = "15";
816 
817   i++; ul_test[i].num = 0xC0000000UL; ul_test[i].expected = "3221225472";
818   i++; ul_test[i].num = 0x0C000000UL; ul_test[i].expected = "201326592";
819   i++; ul_test[i].num = 0x00C00000UL; ul_test[i].expected = "12582912";
820   i++; ul_test[i].num = 0x000C0000UL; ul_test[i].expected = "786432";
821   i++; ul_test[i].num = 0x0000C000UL; ul_test[i].expected = "49152";
822   i++; ul_test[i].num = 0x00000C00UL; ul_test[i].expected = "3072";
823   i++; ul_test[i].num = 0x000000C0UL; ul_test[i].expected = "192";
824   i++; ul_test[i].num = 0x0000000CUL; ul_test[i].expected = "12";
825 
826   i++; ul_test[i].num = 0x00000001UL; ul_test[i].expected = "1";
827   i++; ul_test[i].num = 0x00000000UL; ul_test[i].expected = "0";
828 
829   num_ulong_tests = i;
830 
831 #elif (CURL_SIZEOF_LONG == 8)
832 
833   i=1; ul_test[i].num = 0xFFFFFFFFFFFFFFFFUL; ul_test[i].expected = "18446744073709551615";
834   i++; ul_test[i].num = 0xFFFFFFFF00000000UL; ul_test[i].expected = "18446744069414584320";
835   i++; ul_test[i].num = 0x00000000FFFFFFFFUL; ul_test[i].expected = "4294967295";
836 
837   i++; ul_test[i].num = 0xFFFF000000000000UL; ul_test[i].expected = "18446462598732840960";
838   i++; ul_test[i].num = 0x0000FFFF00000000UL; ul_test[i].expected = "281470681743360";
839   i++; ul_test[i].num = 0x00000000FFFF0000UL; ul_test[i].expected = "4294901760";
840   i++; ul_test[i].num = 0x000000000000FFFFUL; ul_test[i].expected = "65535";
841 
842   i++; ul_test[i].num = 0xFF00000000000000UL; ul_test[i].expected = "18374686479671623680";
843   i++; ul_test[i].num = 0x00FF000000000000UL; ul_test[i].expected = "71776119061217280";
844   i++; ul_test[i].num = 0x0000FF0000000000UL; ul_test[i].expected = "280375465082880";
845   i++; ul_test[i].num = 0x000000FF00000000UL; ul_test[i].expected = "1095216660480";
846   i++; ul_test[i].num = 0x00000000FF000000UL; ul_test[i].expected = "4278190080";
847   i++; ul_test[i].num = 0x0000000000FF0000UL; ul_test[i].expected = "16711680";
848   i++; ul_test[i].num = 0x000000000000FF00UL; ul_test[i].expected = "65280";
849   i++; ul_test[i].num = 0x00000000000000FFUL; ul_test[i].expected = "255";
850 
851   i++; ul_test[i].num = 0xF000000000000000UL; ul_test[i].expected = "17293822569102704640";
852   i++; ul_test[i].num = 0x0F00000000000000UL; ul_test[i].expected = "1080863910568919040";
853   i++; ul_test[i].num = 0x00F0000000000000UL; ul_test[i].expected = "67553994410557440";
854   i++; ul_test[i].num = 0x000F000000000000UL; ul_test[i].expected = "4222124650659840";
855   i++; ul_test[i].num = 0x0000F00000000000UL; ul_test[i].expected = "263882790666240";
856   i++; ul_test[i].num = 0x00000F0000000000UL; ul_test[i].expected = "16492674416640";
857   i++; ul_test[i].num = 0x000000F000000000UL; ul_test[i].expected = "1030792151040";
858   i++; ul_test[i].num = 0x0000000F00000000UL; ul_test[i].expected = "64424509440";
859   i++; ul_test[i].num = 0x00000000F0000000UL; ul_test[i].expected = "4026531840";
860   i++; ul_test[i].num = 0x000000000F000000UL; ul_test[i].expected = "251658240";
861   i++; ul_test[i].num = 0x0000000000F00000UL; ul_test[i].expected = "15728640";
862   i++; ul_test[i].num = 0x00000000000F0000UL; ul_test[i].expected = "983040";
863   i++; ul_test[i].num = 0x000000000000F000UL; ul_test[i].expected = "61440";
864   i++; ul_test[i].num = 0x0000000000000F00UL; ul_test[i].expected = "3840";
865   i++; ul_test[i].num = 0x00000000000000F0UL; ul_test[i].expected = "240";
866   i++; ul_test[i].num = 0x000000000000000FUL; ul_test[i].expected = "15";
867 
868   i++; ul_test[i].num = 0xC000000000000000UL; ul_test[i].expected = "13835058055282163712";
869   i++; ul_test[i].num = 0x0C00000000000000UL; ul_test[i].expected = "864691128455135232";
870   i++; ul_test[i].num = 0x00C0000000000000UL; ul_test[i].expected = "54043195528445952";
871   i++; ul_test[i].num = 0x000C000000000000UL; ul_test[i].expected = "3377699720527872";
872   i++; ul_test[i].num = 0x0000C00000000000UL; ul_test[i].expected = "211106232532992";
873   i++; ul_test[i].num = 0x00000C0000000000UL; ul_test[i].expected = "13194139533312";
874   i++; ul_test[i].num = 0x000000C000000000UL; ul_test[i].expected = "824633720832";
875   i++; ul_test[i].num = 0x0000000C00000000UL; ul_test[i].expected = "51539607552";
876   i++; ul_test[i].num = 0x00000000C0000000UL; ul_test[i].expected = "3221225472";
877   i++; ul_test[i].num = 0x000000000C000000UL; ul_test[i].expected = "201326592";
878   i++; ul_test[i].num = 0x0000000000C00000UL; ul_test[i].expected = "12582912";
879   i++; ul_test[i].num = 0x00000000000C0000UL; ul_test[i].expected = "786432";
880   i++; ul_test[i].num = 0x000000000000C000UL; ul_test[i].expected = "49152";
881   i++; ul_test[i].num = 0x0000000000000C00UL; ul_test[i].expected = "3072";
882   i++; ul_test[i].num = 0x00000000000000C0UL; ul_test[i].expected = "192";
883   i++; ul_test[i].num = 0x000000000000000CUL; ul_test[i].expected = "12";
884 
885   i++; ul_test[i].num = 0x00000001UL; ul_test[i].expected = "1";
886   i++; ul_test[i].num = 0x00000000UL; ul_test[i].expected = "0";
887 
888   num_ulong_tests = i;
889 
890 #endif
891 
892   for(i=1; i<=num_ulong_tests; i++) {
893 
894     for(j=0; j<BUFSZ; j++)
895       ul_test[i].result[j] = 'X';
896     ul_test[i].result[BUFSZ-1] = '\0';
897 
898     (void)curl_msprintf(ul_test[i].result, "%lu", ul_test[i].num);
899 
900     if(memcmp(ul_test[i].result,
901                ul_test[i].expected,
902                strlen(ul_test[i].expected))) {
903       printf("unsigned long test #%.2d: Failed (Expected: %s Got: %s)\n",
904              i, ul_test[i].expected, ul_test[i].result);
905       failed++;
906     }
907 
908   }
909 
910   if(!failed)
911     printf("All curl_mprintf() unsigned long tests OK!\n");
912   else
913     printf("Some curl_mprintf() unsigned long tests Failed!\n");
914 
915   return failed;
916 }
917 
918 
test_signed_long_formatting(void)919 static int test_signed_long_formatting(void)
920 {
921   int i, j;
922   int num_slong_tests;
923   int failed = 0;
924 
925 #if (CURL_SIZEOF_LONG == 2)
926 
927   i=1; sl_test[i].num = 0x7FFFL; sl_test[i].expected = "32767";
928   i++; sl_test[i].num = 0x7FFEL; sl_test[i].expected = "32766";
929   i++; sl_test[i].num = 0x7FFDL; sl_test[i].expected = "32765";
930   i++; sl_test[i].num = 0x7F00L; sl_test[i].expected = "32512";
931   i++; sl_test[i].num = 0x07F0L; sl_test[i].expected = "2032";
932   i++; sl_test[i].num = 0x007FL; sl_test[i].expected = "127";
933 
934   i++; sl_test[i].num = 0x7000L; sl_test[i].expected = "28672";
935   i++; sl_test[i].num = 0x0700L; sl_test[i].expected = "1792";
936   i++; sl_test[i].num = 0x0070L; sl_test[i].expected = "112";
937   i++; sl_test[i].num = 0x0007L; sl_test[i].expected = "7";
938 
939   i++; sl_test[i].num = 0x5000L; sl_test[i].expected = "20480";
940   i++; sl_test[i].num = 0x0500L; sl_test[i].expected = "1280";
941   i++; sl_test[i].num = 0x0050L; sl_test[i].expected = "80";
942   i++; sl_test[i].num = 0x0005L; sl_test[i].expected = "5";
943 
944   i++; sl_test[i].num = 0x0001L; sl_test[i].expected = "1";
945   i++; sl_test[i].num = 0x0000L; sl_test[i].expected = "0";
946 
947   i++; sl_test[i].num = -0x7FFFL -1L; sl_test[i].expected = "-32768";
948   i++; sl_test[i].num = -0x7FFEL -1L; sl_test[i].expected = "-32767";
949   i++; sl_test[i].num = -0x7FFDL -1L; sl_test[i].expected = "-32766";
950   i++; sl_test[i].num = -0x7F00L -1L; sl_test[i].expected = "-32513";
951   i++; sl_test[i].num = -0x07F0L -1L; sl_test[i].expected = "-2033";
952   i++; sl_test[i].num = -0x007FL -1L; sl_test[i].expected = "-128";
953 
954   i++; sl_test[i].num = -0x7000L -1L; sl_test[i].expected = "-28673";
955   i++; sl_test[i].num = -0x0700L -1L; sl_test[i].expected = "-1793";
956   i++; sl_test[i].num = -0x0070L -1L; sl_test[i].expected = "-113";
957   i++; sl_test[i].num = -0x0007L -1L; sl_test[i].expected = "-8";
958 
959   i++; sl_test[i].num = -0x5000L -1L; sl_test[i].expected = "-20481";
960   i++; sl_test[i].num = -0x0500L -1L; sl_test[i].expected = "-1281";
961   i++; sl_test[i].num = -0x0050L -1L; sl_test[i].expected = "-81";
962   i++; sl_test[i].num = -0x0005L -1L; sl_test[i].expected = "-6";
963 
964   i++; sl_test[i].num =  0x0000L -1L; sl_test[i].expected = "-1";
965 
966   num_slong_tests = i;
967 
968 #elif (CURL_SIZEOF_LONG == 4)
969 
970   i=1; sl_test[i].num = 0x7FFFFFFFL; sl_test[i].expected = "2147483647";
971   i++; sl_test[i].num = 0x7FFFFFFEL; sl_test[i].expected = "2147483646";
972   i++; sl_test[i].num = 0x7FFFFFFDL; sl_test[i].expected = "2147483645";
973   i++; sl_test[i].num = 0x7FFF0000L; sl_test[i].expected = "2147418112";
974   i++; sl_test[i].num = 0x00007FFFL; sl_test[i].expected = "32767";
975 
976   i++; sl_test[i].num = 0x7F000000L; sl_test[i].expected = "2130706432";
977   i++; sl_test[i].num = 0x007F0000L; sl_test[i].expected = "8323072";
978   i++; sl_test[i].num = 0x00007F00L; sl_test[i].expected = "32512";
979   i++; sl_test[i].num = 0x0000007FL; sl_test[i].expected = "127";
980 
981   i++; sl_test[i].num = 0x70000000L; sl_test[i].expected = "1879048192";
982   i++; sl_test[i].num = 0x07000000L; sl_test[i].expected = "117440512";
983   i++; sl_test[i].num = 0x00700000L; sl_test[i].expected = "7340032";
984   i++; sl_test[i].num = 0x00070000L; sl_test[i].expected = "458752";
985   i++; sl_test[i].num = 0x00007000L; sl_test[i].expected = "28672";
986   i++; sl_test[i].num = 0x00000700L; sl_test[i].expected = "1792";
987   i++; sl_test[i].num = 0x00000070L; sl_test[i].expected = "112";
988   i++; sl_test[i].num = 0x00000007L; sl_test[i].expected = "7";
989 
990   i++; sl_test[i].num = 0x50000000L; sl_test[i].expected = "1342177280";
991   i++; sl_test[i].num = 0x05000000L; sl_test[i].expected = "83886080";
992   i++; sl_test[i].num = 0x00500000L; sl_test[i].expected = "5242880";
993   i++; sl_test[i].num = 0x00050000L; sl_test[i].expected = "327680";
994   i++; sl_test[i].num = 0x00005000L; sl_test[i].expected = "20480";
995   i++; sl_test[i].num = 0x00000500L; sl_test[i].expected = "1280";
996   i++; sl_test[i].num = 0x00000050L; sl_test[i].expected = "80";
997   i++; sl_test[i].num = 0x00000005L; sl_test[i].expected = "5";
998 
999   i++; sl_test[i].num = 0x00000001L; sl_test[i].expected = "1";
1000   i++; sl_test[i].num = 0x00000000L; sl_test[i].expected = "0";
1001 
1002   i++; sl_test[i].num = -0x7FFFFFFFL -1L; sl_test[i].expected = "-2147483648";
1003   i++; sl_test[i].num = -0x7FFFFFFEL -1L; sl_test[i].expected = "-2147483647";
1004   i++; sl_test[i].num = -0x7FFFFFFDL -1L; sl_test[i].expected = "-2147483646";
1005   i++; sl_test[i].num = -0x7FFF0000L -1L; sl_test[i].expected = "-2147418113";
1006   i++; sl_test[i].num = -0x00007FFFL -1L; sl_test[i].expected = "-32768";
1007 
1008   i++; sl_test[i].num = -0x7F000000L -1L; sl_test[i].expected = "-2130706433";
1009   i++; sl_test[i].num = -0x007F0000L -1L; sl_test[i].expected = "-8323073";
1010   i++; sl_test[i].num = -0x00007F00L -1L; sl_test[i].expected = "-32513";
1011   i++; sl_test[i].num = -0x0000007FL -1L; sl_test[i].expected = "-128";
1012 
1013   i++; sl_test[i].num = -0x70000000L -1L; sl_test[i].expected = "-1879048193";
1014   i++; sl_test[i].num = -0x07000000L -1L; sl_test[i].expected = "-117440513";
1015   i++; sl_test[i].num = -0x00700000L -1L; sl_test[i].expected = "-7340033";
1016   i++; sl_test[i].num = -0x00070000L -1L; sl_test[i].expected = "-458753";
1017   i++; sl_test[i].num = -0x00007000L -1L; sl_test[i].expected = "-28673";
1018   i++; sl_test[i].num = -0x00000700L -1L; sl_test[i].expected = "-1793";
1019   i++; sl_test[i].num = -0x00000070L -1L; sl_test[i].expected = "-113";
1020   i++; sl_test[i].num = -0x00000007L -1L; sl_test[i].expected = "-8";
1021 
1022   i++; sl_test[i].num = -0x50000000L -1L; sl_test[i].expected = "-1342177281";
1023   i++; sl_test[i].num = -0x05000000L -1L; sl_test[i].expected = "-83886081";
1024   i++; sl_test[i].num = -0x00500000L -1L; sl_test[i].expected = "-5242881";
1025   i++; sl_test[i].num = -0x00050000L -1L; sl_test[i].expected = "-327681";
1026   i++; sl_test[i].num = -0x00005000L -1L; sl_test[i].expected = "-20481";
1027   i++; sl_test[i].num = -0x00000500L -1L; sl_test[i].expected = "-1281";
1028   i++; sl_test[i].num = -0x00000050L -1L; sl_test[i].expected = "-81";
1029   i++; sl_test[i].num = -0x00000005L -1L; sl_test[i].expected = "-6";
1030 
1031   i++; sl_test[i].num =  0x00000000L -1L; sl_test[i].expected = "-1";
1032 
1033   num_slong_tests = i;
1034 
1035 #elif (CURL_SIZEOF_LONG == 8)
1036 
1037   i=1; sl_test[i].num = 0x7FFFFFFFFFFFFFFFL; sl_test[i].expected = "9223372036854775807";
1038   i++; sl_test[i].num = 0x7FFFFFFFFFFFFFFEL; sl_test[i].expected = "9223372036854775806";
1039   i++; sl_test[i].num = 0x7FFFFFFFFFFFFFFDL; sl_test[i].expected = "9223372036854775805";
1040   i++; sl_test[i].num = 0x7FFFFFFF00000000L; sl_test[i].expected = "9223372032559808512";
1041   i++; sl_test[i].num = 0x000000007FFFFFFFL; sl_test[i].expected = "2147483647";
1042 
1043   i++; sl_test[i].num = 0x7FFF000000000000L; sl_test[i].expected = "9223090561878065152";
1044   i++; sl_test[i].num = 0x00007FFF00000000L; sl_test[i].expected = "140733193388032";
1045   i++; sl_test[i].num = 0x000000007FFF0000L; sl_test[i].expected = "2147418112";
1046   i++; sl_test[i].num = 0x0000000000007FFFL; sl_test[i].expected = "32767";
1047 
1048   i++; sl_test[i].num = 0x7F00000000000000L; sl_test[i].expected = "9151314442816847872";
1049   i++; sl_test[i].num = 0x007F000000000000L; sl_test[i].expected = "35747322042253312";
1050   i++; sl_test[i].num = 0x00007F0000000000L; sl_test[i].expected = "139637976727552";
1051   i++; sl_test[i].num = 0x0000007F00000000L; sl_test[i].expected = "545460846592";
1052   i++; sl_test[i].num = 0x000000007F000000L; sl_test[i].expected = "2130706432";
1053   i++; sl_test[i].num = 0x00000000007F0000L; sl_test[i].expected = "8323072";
1054   i++; sl_test[i].num = 0x0000000000007F00L; sl_test[i].expected = "32512";
1055   i++; sl_test[i].num = 0x000000000000007FL; sl_test[i].expected = "127";
1056 
1057   i++; sl_test[i].num = 0x7000000000000000L; sl_test[i].expected = "8070450532247928832";
1058   i++; sl_test[i].num = 0x0700000000000000L; sl_test[i].expected = "504403158265495552";
1059   i++; sl_test[i].num = 0x0070000000000000L; sl_test[i].expected = "31525197391593472";
1060   i++; sl_test[i].num = 0x0007000000000000L; sl_test[i].expected = "1970324836974592";
1061   i++; sl_test[i].num = 0x0000700000000000L; sl_test[i].expected = "123145302310912";
1062   i++; sl_test[i].num = 0x0000070000000000L; sl_test[i].expected = "7696581394432";
1063   i++; sl_test[i].num = 0x0000007000000000L; sl_test[i].expected = "481036337152";
1064   i++; sl_test[i].num = 0x0000000700000000L; sl_test[i].expected = "30064771072";
1065   i++; sl_test[i].num = 0x0000000070000000L; sl_test[i].expected = "1879048192";
1066   i++; sl_test[i].num = 0x0000000007000000L; sl_test[i].expected = "117440512";
1067   i++; sl_test[i].num = 0x0000000000700000L; sl_test[i].expected = "7340032";
1068   i++; sl_test[i].num = 0x0000000000070000L; sl_test[i].expected = "458752";
1069   i++; sl_test[i].num = 0x0000000000007000L; sl_test[i].expected = "28672";
1070   i++; sl_test[i].num = 0x0000000000000700L; sl_test[i].expected = "1792";
1071   i++; sl_test[i].num = 0x0000000000000070L; sl_test[i].expected = "112";
1072   i++; sl_test[i].num = 0x0000000000000007L; sl_test[i].expected = "7";
1073 
1074   i++; sl_test[i].num = 0x0000000000000001L; sl_test[i].expected = "1";
1075   i++; sl_test[i].num = 0x0000000000000000L; sl_test[i].expected = "0";
1076 
1077   i++; sl_test[i].num = -0x7FFFFFFFFFFFFFFFL -1L; sl_test[i].expected = "-9223372036854775808";
1078   i++; sl_test[i].num = -0x7FFFFFFFFFFFFFFEL -1L; sl_test[i].expected = "-9223372036854775807";
1079   i++; sl_test[i].num = -0x7FFFFFFFFFFFFFFDL -1L; sl_test[i].expected = "-9223372036854775806";
1080   i++; sl_test[i].num = -0x7FFFFFFF00000000L -1L; sl_test[i].expected = "-9223372032559808513";
1081   i++; sl_test[i].num = -0x000000007FFFFFFFL -1L; sl_test[i].expected = "-2147483648";
1082 
1083   i++; sl_test[i].num = -0x7FFF000000000000L -1L; sl_test[i].expected = "-9223090561878065153";
1084   i++; sl_test[i].num = -0x00007FFF00000000L -1L; sl_test[i].expected = "-140733193388033";
1085   i++; sl_test[i].num = -0x000000007FFF0000L -1L; sl_test[i].expected = "-2147418113";
1086   i++; sl_test[i].num = -0x0000000000007FFFL -1L; sl_test[i].expected = "-32768";
1087 
1088   i++; sl_test[i].num = -0x7F00000000000000L -1L; sl_test[i].expected = "-9151314442816847873";
1089   i++; sl_test[i].num = -0x007F000000000000L -1L; sl_test[i].expected = "-35747322042253313";
1090   i++; sl_test[i].num = -0x00007F0000000000L -1L; sl_test[i].expected = "-139637976727553";
1091   i++; sl_test[i].num = -0x0000007F00000000L -1L; sl_test[i].expected = "-545460846593";
1092   i++; sl_test[i].num = -0x000000007F000000L -1L; sl_test[i].expected = "-2130706433";
1093   i++; sl_test[i].num = -0x00000000007F0000L -1L; sl_test[i].expected = "-8323073";
1094   i++; sl_test[i].num = -0x0000000000007F00L -1L; sl_test[i].expected = "-32513";
1095   i++; sl_test[i].num = -0x000000000000007FL -1L; sl_test[i].expected = "-128";
1096 
1097   i++; sl_test[i].num = -0x7000000000000000L -1L; sl_test[i].expected = "-8070450532247928833";
1098   i++; sl_test[i].num = -0x0700000000000000L -1L; sl_test[i].expected = "-504403158265495553";
1099   i++; sl_test[i].num = -0x0070000000000000L -1L; sl_test[i].expected = "-31525197391593473";
1100   i++; sl_test[i].num = -0x0007000000000000L -1L; sl_test[i].expected = "-1970324836974593";
1101   i++; sl_test[i].num = -0x0000700000000000L -1L; sl_test[i].expected = "-123145302310913";
1102   i++; sl_test[i].num = -0x0000070000000000L -1L; sl_test[i].expected = "-7696581394433";
1103   i++; sl_test[i].num = -0x0000007000000000L -1L; sl_test[i].expected = "-481036337153";
1104   i++; sl_test[i].num = -0x0000000700000000L -1L; sl_test[i].expected = "-30064771073";
1105   i++; sl_test[i].num = -0x0000000070000000L -1L; sl_test[i].expected = "-1879048193";
1106   i++; sl_test[i].num = -0x0000000007000000L -1L; sl_test[i].expected = "-117440513";
1107   i++; sl_test[i].num = -0x0000000000700000L -1L; sl_test[i].expected = "-7340033";
1108   i++; sl_test[i].num = -0x0000000000070000L -1L; sl_test[i].expected = "-458753";
1109   i++; sl_test[i].num = -0x0000000000007000L -1L; sl_test[i].expected = "-28673";
1110   i++; sl_test[i].num = -0x0000000000000700L -1L; sl_test[i].expected = "-1793";
1111   i++; sl_test[i].num = -0x0000000000000070L -1L; sl_test[i].expected = "-113";
1112   i++; sl_test[i].num = -0x0000000000000007L -1L; sl_test[i].expected = "-8";
1113 
1114   i++; sl_test[i].num =  0x0000000000000000L -1L; sl_test[i].expected = "-1";
1115 
1116   num_slong_tests = i;
1117 
1118 #endif
1119 
1120   for(i=1; i<=num_slong_tests; i++) {
1121 
1122     for(j=0; j<BUFSZ; j++)
1123       sl_test[i].result[j] = 'X';
1124     sl_test[i].result[BUFSZ-1] = '\0';
1125 
1126     (void)curl_msprintf(sl_test[i].result, "%ld", sl_test[i].num);
1127 
1128     if(memcmp(sl_test[i].result,
1129               sl_test[i].expected,
1130               strlen(sl_test[i].expected))) {
1131       printf("signed long test #%.2d: Failed (Expected: %s Got: %s)\n",
1132              i, sl_test[i].expected, sl_test[i].result);
1133       failed++;
1134     }
1135 
1136   }
1137 
1138   if(!failed)
1139     printf("All curl_mprintf() signed long tests OK!\n");
1140   else
1141     printf("Some curl_mprintf() signed long tests Failed!\n");
1142 
1143   return failed;
1144 }
1145 
1146 
test_curl_off_t_formatting(void)1147 static int test_curl_off_t_formatting(void)
1148 {
1149   int i, j;
1150   int num_cofft_tests;
1151   int failed = 0;
1152 
1153 #if (CURL_SIZEOF_CURL_OFF_T == 2)
1154 
1155   i=1; co_test[i].num = MPRNT_OFF_T_C(0x7FFF); co_test[i].expected = "32767";
1156   i++; co_test[i].num = MPRNT_OFF_T_C(0x7FFE); co_test[i].expected = "32766";
1157   i++; co_test[i].num = MPRNT_OFF_T_C(0x7FFD); co_test[i].expected = "32765";
1158   i++; co_test[i].num = MPRNT_OFF_T_C(0x7F00); co_test[i].expected = "32512";
1159   i++; co_test[i].num = MPRNT_OFF_T_C(0x07F0); co_test[i].expected = "2032";
1160   i++; co_test[i].num = MPRNT_OFF_T_C(0x007F); co_test[i].expected = "127";
1161 
1162   i++; co_test[i].num = MPRNT_OFF_T_C(0x7000); co_test[i].expected = "28672";
1163   i++; co_test[i].num = MPRNT_OFF_T_C(0x0700); co_test[i].expected = "1792";
1164   i++; co_test[i].num = MPRNT_OFF_T_C(0x0070); co_test[i].expected = "112";
1165   i++; co_test[i].num = MPRNT_OFF_T_C(0x0007); co_test[i].expected = "7";
1166 
1167   i++; co_test[i].num = MPRNT_OFF_T_C(0x5000); co_test[i].expected = "20480";
1168   i++; co_test[i].num = MPRNT_OFF_T_C(0x0500); co_test[i].expected = "1280";
1169   i++; co_test[i].num = MPRNT_OFF_T_C(0x0050); co_test[i].expected = "80";
1170   i++; co_test[i].num = MPRNT_OFF_T_C(0x0005); co_test[i].expected = "5";
1171 
1172   i++; co_test[i].num = MPRNT_OFF_T_C(0x0001); co_test[i].expected = "1";
1173   i++; co_test[i].num = MPRNT_OFF_T_C(0x0000); co_test[i].expected = "0";
1174 
1175   i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFF) -MPRNT_OFF_T_C(1); co_test[i].expected = "-32768";
1176   i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFE) -MPRNT_OFF_T_C(1); co_test[i].expected = "-32767";
1177   i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFD) -MPRNT_OFF_T_C(1); co_test[i].expected = "-32766";
1178   i++; co_test[i].num = -MPRNT_OFF_T_C(0x7F00) -MPRNT_OFF_T_C(1); co_test[i].expected = "-32513";
1179   i++; co_test[i].num = -MPRNT_OFF_T_C(0x07F0) -MPRNT_OFF_T_C(1); co_test[i].expected = "-2033";
1180   i++; co_test[i].num = -MPRNT_OFF_T_C(0x007F) -MPRNT_OFF_T_C(1); co_test[i].expected = "-128";
1181 
1182   i++; co_test[i].num = -MPRNT_OFF_T_C(0x7000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-28673";
1183   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0700) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1793";
1184   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0070) -MPRNT_OFF_T_C(1); co_test[i].expected = "-113";
1185   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0007) -MPRNT_OFF_T_C(1); co_test[i].expected = "-8";
1186 
1187   i++; co_test[i].num = -MPRNT_OFF_T_C(0x5000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-20481";
1188   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0500) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1281";
1189   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0050) -MPRNT_OFF_T_C(1); co_test[i].expected = "-81";
1190   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0005) -MPRNT_OFF_T_C(1); co_test[i].expected = "-6";
1191 
1192   i++; co_test[i].num =  MPRNT_OFF_T_C(0x0000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1";
1193 
1194   num_cofft_tests = i;
1195 
1196 #elif (CURL_SIZEOF_CURL_OFF_T == 4)
1197 
1198   i=1; co_test[i].num = MPRNT_OFF_T_C(0x7FFFFFFF); co_test[i].expected = "2147483647";
1199   i++; co_test[i].num = MPRNT_OFF_T_C(0x7FFFFFFE); co_test[i].expected = "2147483646";
1200   i++; co_test[i].num = MPRNT_OFF_T_C(0x7FFFFFFD); co_test[i].expected = "2147483645";
1201   i++; co_test[i].num = MPRNT_OFF_T_C(0x7FFF0000); co_test[i].expected = "2147418112";
1202   i++; co_test[i].num = MPRNT_OFF_T_C(0x00007FFF); co_test[i].expected = "32767";
1203 
1204   i++; co_test[i].num = MPRNT_OFF_T_C(0x7F000000); co_test[i].expected = "2130706432";
1205   i++; co_test[i].num = MPRNT_OFF_T_C(0x007F0000); co_test[i].expected = "8323072";
1206   i++; co_test[i].num = MPRNT_OFF_T_C(0x00007F00); co_test[i].expected = "32512";
1207   i++; co_test[i].num = MPRNT_OFF_T_C(0x0000007F); co_test[i].expected = "127";
1208 
1209   i++; co_test[i].num = MPRNT_OFF_T_C(0x70000000); co_test[i].expected = "1879048192";
1210   i++; co_test[i].num = MPRNT_OFF_T_C(0x07000000); co_test[i].expected = "117440512";
1211   i++; co_test[i].num = MPRNT_OFF_T_C(0x00700000); co_test[i].expected = "7340032";
1212   i++; co_test[i].num = MPRNT_OFF_T_C(0x00070000); co_test[i].expected = "458752";
1213   i++; co_test[i].num = MPRNT_OFF_T_C(0x00007000); co_test[i].expected = "28672";
1214   i++; co_test[i].num = MPRNT_OFF_T_C(0x00000700); co_test[i].expected = "1792";
1215   i++; co_test[i].num = MPRNT_OFF_T_C(0x00000070); co_test[i].expected = "112";
1216   i++; co_test[i].num = MPRNT_OFF_T_C(0x00000007); co_test[i].expected = "7";
1217 
1218   i++; co_test[i].num = MPRNT_OFF_T_C(0x50000000); co_test[i].expected = "1342177280";
1219   i++; co_test[i].num = MPRNT_OFF_T_C(0x05000000); co_test[i].expected = "83886080";
1220   i++; co_test[i].num = MPRNT_OFF_T_C(0x00500000); co_test[i].expected = "5242880";
1221   i++; co_test[i].num = MPRNT_OFF_T_C(0x00050000); co_test[i].expected = "327680";
1222   i++; co_test[i].num = MPRNT_OFF_T_C(0x00005000); co_test[i].expected = "20480";
1223   i++; co_test[i].num = MPRNT_OFF_T_C(0x00000500); co_test[i].expected = "1280";
1224   i++; co_test[i].num = MPRNT_OFF_T_C(0x00000050); co_test[i].expected = "80";
1225   i++; co_test[i].num = MPRNT_OFF_T_C(0x00000005); co_test[i].expected = "5";
1226 
1227   i++; co_test[i].num = MPRNT_OFF_T_C(0x00000001); co_test[i].expected = "1";
1228   i++; co_test[i].num = MPRNT_OFF_T_C(0x00000000); co_test[i].expected = "0";
1229 
1230   i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFFFFFF) -MPRNT_OFF_T_C(1); co_test[i].expected = "-2147483648";
1231   i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFFFFFE) -MPRNT_OFF_T_C(1); co_test[i].expected = "-2147483647";
1232   i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFFFFFD) -MPRNT_OFF_T_C(1); co_test[i].expected = "-2147483646";
1233   i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFF0000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-2147418113";
1234   i++; co_test[i].num = -MPRNT_OFF_T_C(0x00007FFF) -MPRNT_OFF_T_C(1); co_test[i].expected = "-32768";
1235 
1236   i++; co_test[i].num = -MPRNT_OFF_T_C(0x7F000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-2130706433";
1237   i++; co_test[i].num = -MPRNT_OFF_T_C(0x007F0000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-8323073";
1238   i++; co_test[i].num = -MPRNT_OFF_T_C(0x00007F00) -MPRNT_OFF_T_C(1); co_test[i].expected = "-32513";
1239   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000007F) -MPRNT_OFF_T_C(1); co_test[i].expected = "-128";
1240 
1241   i++; co_test[i].num = -MPRNT_OFF_T_C(0x70000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1879048193";
1242   i++; co_test[i].num = -MPRNT_OFF_T_C(0x07000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-117440513";
1243   i++; co_test[i].num = -MPRNT_OFF_T_C(0x00700000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-7340033";
1244   i++; co_test[i].num = -MPRNT_OFF_T_C(0x00070000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-458753";
1245   i++; co_test[i].num = -MPRNT_OFF_T_C(0x00007000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-28673";
1246   i++; co_test[i].num = -MPRNT_OFF_T_C(0x00000700) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1793";
1247   i++; co_test[i].num = -MPRNT_OFF_T_C(0x00000070) -MPRNT_OFF_T_C(1); co_test[i].expected = "-113";
1248   i++; co_test[i].num = -MPRNT_OFF_T_C(0x00000007) -MPRNT_OFF_T_C(1); co_test[i].expected = "-8";
1249 
1250   i++; co_test[i].num = -MPRNT_OFF_T_C(0x50000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1342177281";
1251   i++; co_test[i].num = -MPRNT_OFF_T_C(0x05000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-83886081";
1252   i++; co_test[i].num = -MPRNT_OFF_T_C(0x00500000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-5242881";
1253   i++; co_test[i].num = -MPRNT_OFF_T_C(0x00050000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-327681";
1254   i++; co_test[i].num = -MPRNT_OFF_T_C(0x00005000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-20481";
1255   i++; co_test[i].num = -MPRNT_OFF_T_C(0x00000500) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1281";
1256   i++; co_test[i].num = -MPRNT_OFF_T_C(0x00000050) -MPRNT_OFF_T_C(1); co_test[i].expected = "-81";
1257   i++; co_test[i].num = -MPRNT_OFF_T_C(0x00000005) -MPRNT_OFF_T_C(1); co_test[i].expected = "-6";
1258 
1259   i++; co_test[i].num =  MPRNT_OFF_T_C(0x00000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1";
1260 
1261   num_cofft_tests = i;
1262 
1263 #elif (CURL_SIZEOF_CURL_OFF_T == 8)
1264 
1265   i=1; co_test[i].num = MPRNT_OFF_T_C(0x7FFFFFFFFFFFFFFF); co_test[i].expected = "9223372036854775807";
1266   i++; co_test[i].num = MPRNT_OFF_T_C(0x7FFFFFFFFFFFFFFE); co_test[i].expected = "9223372036854775806";
1267   i++; co_test[i].num = MPRNT_OFF_T_C(0x7FFFFFFFFFFFFFFD); co_test[i].expected = "9223372036854775805";
1268   i++; co_test[i].num = MPRNT_OFF_T_C(0x7FFFFFFF00000000); co_test[i].expected = "9223372032559808512";
1269   i++; co_test[i].num = MPRNT_OFF_T_C(0x000000007FFFFFFF); co_test[i].expected = "2147483647";
1270 
1271   i++; co_test[i].num = MPRNT_OFF_T_C(0x7FFF000000000000); co_test[i].expected = "9223090561878065152";
1272   i++; co_test[i].num = MPRNT_OFF_T_C(0x00007FFF00000000); co_test[i].expected = "140733193388032";
1273   i++; co_test[i].num = MPRNT_OFF_T_C(0x000000007FFF0000); co_test[i].expected = "2147418112";
1274   i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000007FFF); co_test[i].expected = "32767";
1275 
1276   i++; co_test[i].num = MPRNT_OFF_T_C(0x7F00000000000000); co_test[i].expected = "9151314442816847872";
1277   i++; co_test[i].num = MPRNT_OFF_T_C(0x007F000000000000); co_test[i].expected = "35747322042253312";
1278   i++; co_test[i].num = MPRNT_OFF_T_C(0x00007F0000000000); co_test[i].expected = "139637976727552";
1279   i++; co_test[i].num = MPRNT_OFF_T_C(0x0000007F00000000); co_test[i].expected = "545460846592";
1280   i++; co_test[i].num = MPRNT_OFF_T_C(0x000000007F000000); co_test[i].expected = "2130706432";
1281   i++; co_test[i].num = MPRNT_OFF_T_C(0x00000000007F0000); co_test[i].expected = "8323072";
1282   i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000007F00); co_test[i].expected = "32512";
1283   i++; co_test[i].num = MPRNT_OFF_T_C(0x000000000000007F); co_test[i].expected = "127";
1284 
1285   i++; co_test[i].num = MPRNT_OFF_T_C(0x7000000000000000); co_test[i].expected = "8070450532247928832";
1286   i++; co_test[i].num = MPRNT_OFF_T_C(0x0700000000000000); co_test[i].expected = "504403158265495552";
1287   i++; co_test[i].num = MPRNT_OFF_T_C(0x0070000000000000); co_test[i].expected = "31525197391593472";
1288   i++; co_test[i].num = MPRNT_OFF_T_C(0x0007000000000000); co_test[i].expected = "1970324836974592";
1289   i++; co_test[i].num = MPRNT_OFF_T_C(0x0000700000000000); co_test[i].expected = "123145302310912";
1290   i++; co_test[i].num = MPRNT_OFF_T_C(0x0000070000000000); co_test[i].expected = "7696581394432";
1291   i++; co_test[i].num = MPRNT_OFF_T_C(0x0000007000000000); co_test[i].expected = "481036337152";
1292   i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000700000000); co_test[i].expected = "30064771072";
1293   i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000070000000); co_test[i].expected = "1879048192";
1294   i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000007000000); co_test[i].expected = "117440512";
1295   i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000700000); co_test[i].expected = "7340032";
1296   i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000070000); co_test[i].expected = "458752";
1297   i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000007000); co_test[i].expected = "28672";
1298   i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000000700); co_test[i].expected = "1792";
1299   i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000000070); co_test[i].expected = "112";
1300   i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000000007); co_test[i].expected = "7";
1301 
1302   i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000000001); co_test[i].expected = "1";
1303   i++; co_test[i].num = MPRNT_OFF_T_C(0x0000000000000000); co_test[i].expected = "0";
1304 
1305   i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFFFFFFFFFFFFFF) -MPRNT_OFF_T_C(1); co_test[i].expected = "-9223372036854775808";
1306   i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFFFFFFFFFFFFFE) -MPRNT_OFF_T_C(1); co_test[i].expected = "-9223372036854775807";
1307   i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFFFFFFFFFFFFFD) -MPRNT_OFF_T_C(1); co_test[i].expected = "-9223372036854775806";
1308   i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFFFFFF00000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-9223372032559808513";
1309   i++; co_test[i].num = -MPRNT_OFF_T_C(0x000000007FFFFFFF) -MPRNT_OFF_T_C(1); co_test[i].expected = "-2147483648";
1310 
1311   i++; co_test[i].num = -MPRNT_OFF_T_C(0x7FFF000000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-9223090561878065153";
1312   i++; co_test[i].num = -MPRNT_OFF_T_C(0x00007FFF00000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-140733193388033";
1313   i++; co_test[i].num = -MPRNT_OFF_T_C(0x000000007FFF0000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-2147418113";
1314   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000000007FFF) -MPRNT_OFF_T_C(1); co_test[i].expected = "-32768";
1315 
1316   i++; co_test[i].num = -MPRNT_OFF_T_C(0x7F00000000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-9151314442816847873";
1317   i++; co_test[i].num = -MPRNT_OFF_T_C(0x007F000000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-35747322042253313";
1318   i++; co_test[i].num = -MPRNT_OFF_T_C(0x00007F0000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-139637976727553";
1319   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000007F00000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-545460846593";
1320   i++; co_test[i].num = -MPRNT_OFF_T_C(0x000000007F000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-2130706433";
1321   i++; co_test[i].num = -MPRNT_OFF_T_C(0x00000000007F0000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-8323073";
1322   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000000007F00) -MPRNT_OFF_T_C(1); co_test[i].expected = "-32513";
1323   i++; co_test[i].num = -MPRNT_OFF_T_C(0x000000000000007F) -MPRNT_OFF_T_C(1); co_test[i].expected = "-128";
1324 
1325   i++; co_test[i].num = -MPRNT_OFF_T_C(0x7000000000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-8070450532247928833";
1326   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0700000000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-504403158265495553";
1327   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0070000000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-31525197391593473";
1328   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0007000000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1970324836974593";
1329   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000700000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-123145302310913";
1330   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000070000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-7696581394433";
1331   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000007000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-481036337153";
1332   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000700000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-30064771073";
1333   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000070000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1879048193";
1334   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000007000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-117440513";
1335   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000000700000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-7340033";
1336   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000000070000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-458753";
1337   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000000007000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-28673";
1338   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000000000700) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1793";
1339   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000000000070) -MPRNT_OFF_T_C(1); co_test[i].expected = "-113";
1340   i++; co_test[i].num = -MPRNT_OFF_T_C(0x0000000000000007) -MPRNT_OFF_T_C(1); co_test[i].expected = "-8";
1341 
1342   i++; co_test[i].num =  MPRNT_OFF_T_C(0x0000000000000000) -MPRNT_OFF_T_C(1); co_test[i].expected = "-1";
1343 
1344   num_cofft_tests = i;
1345 
1346 #endif
1347 
1348   for(i=1; i<=num_cofft_tests; i++) {
1349 
1350     for(j=0; j<BUFSZ; j++)
1351       co_test[i].result[j] = 'X';
1352     co_test[i].result[BUFSZ-1] = '\0';
1353 
1354     (void)curl_msprintf(co_test[i].result, "%" CURL_FORMAT_CURL_OFF_T, co_test[i].num);
1355 
1356     if(memcmp(co_test[i].result,
1357                co_test[i].expected,
1358                strlen(co_test[i].expected))) {
1359       printf("curl_off_t test #%.2d: Failed (Expected: %s Got: %s)\n",
1360              i, co_test[i].expected, co_test[i].result);
1361       failed++;
1362     }
1363 
1364   }
1365 
1366   if(!failed)
1367     printf("All curl_mprintf() curl_off_t tests OK!\n");
1368   else
1369     printf("Some curl_mprintf() curl_off_t tests Failed!\n");
1370 
1371   return failed;
1372 }
1373 
1374 
test(char * URL)1375 int test(char *URL)
1376 {
1377   int errors = 0;
1378   (void)URL; /* not used */
1379 
1380   errors += test_unsigned_short_formatting();
1381 
1382   errors += test_signed_short_formatting();
1383 
1384   errors += test_unsigned_int_formatting();
1385 
1386   errors += test_signed_int_formatting();
1387 
1388   errors += test_unsigned_long_formatting();
1389 
1390   errors += test_signed_long_formatting();
1391 
1392   errors += test_curl_off_t_formatting();
1393 
1394   if(errors)
1395     return TEST_ERR_MAJOR_BAD;
1396   else
1397     return 0;
1398 }
1399