The MinGW.org Windows System Libraries
修订版 | 21718add2560a3103b881327bee3779b06a488ff (tree) |
---|---|
时间 | 2019-07-04 05:49:42 |
作者 | Keith Marshall <keith@user...> |
Commiter | Keith Marshall |
Avoid built-in snprintf() prototypes; fix MinGW-Bug #39224
@@ -1,3 +1,20 @@ | ||
1 | +2019-07-03 Keith Marshall <keith@users.osdn.me> | |
2 | + | |
3 | + Avoid built-in snprintf() prototypes; fix MinGW-Bug #39224 | |
4 | + | |
5 | + * include/stdio.h [__USE_MINGW_ANSI_STDIO] | |
6 | + (snprintf, vsnprintf): Implement them in-line, delegating to... | |
7 | + (__mingw_vsnprintf): ...this external function. | |
8 | + | |
9 | + * mingwex/stdio/snprintf.c mingwex/stdio/vsnprintf.c: Assert | |
10 | + copyright; include <stddef.h>, instead of <stdio.h>, to obtain a | |
11 | + definition of "size_t"; this is required because the new in-line | |
12 | + prototypes, now provided in <stdio.h>, conflict with the intent | |
13 | + to provide external implementations. | |
14 | + | |
15 | + * tests/ansiprintf.at (MINGW_AT_CHECK_SNPRINTF): Conditionally | |
16 | + circumvent conditions which may produce -Wformat warnings. | |
17 | + | |
1 | 18 | 2019-07-01 Keith Marshall <keith@users.osdn.me> |
2 | 19 | |
3 | 20 | Revert to macro implementation of "alloca()" functions. |
@@ -375,7 +375,7 @@ extern int __mingw_stdio_redirect__(vsnprintf)(char*, size_t, const char*, __VAL | ||
375 | 375 | */ |
376 | 376 | extern unsigned int _mingw_output_format_control( unsigned int, unsigned int ); |
377 | 377 | |
378 | -#if __USE_MINGW_ANSI_STDIO | |
378 | +#if __USE_MINGW_ANSI_STDIO || defined _ISOC99_SOURCE | |
379 | 379 | /* User has expressed a preference for C99 conformance... |
380 | 380 | */ |
381 | 381 | # undef __mingw_stdio_redirect__ |
@@ -393,12 +393,20 @@ extern unsigned int _mingw_output_format_control( unsigned int, unsigned int ); | ||
393 | 393 | */ |
394 | 394 | # define __mingw_stdio_redirect__ static __inline__ __cdecl __MINGW_NOTHROW |
395 | 395 | |
396 | -# else | |
396 | +# else /* Neither C++ nor __GNUC__ */ | |
397 | 397 | /* Can't use inlines; fall back on module local static stubs. |
398 | 398 | */ |
399 | 399 | # define __mingw_stdio_redirect__ static __cdecl __MINGW_NOTHROW |
400 | -# endif | |
401 | 400 | |
401 | +# endif /* Neither C++ nor __GNUC__ */ | |
402 | +#endif /* __USE_MINGW_ANSI_STDIO || defined _ISOC99_SOURCE */ | |
403 | + | |
404 | +#if __USE_MINGW_ANSI_STDIO | |
405 | +/* The MinGW ISO-C conforming implementations of the printf() family | |
406 | + * of functions are to be used, in place of non-conforming Microsoft | |
407 | + * implementations; force call redirection, via the following set of | |
408 | + * in-line functions. | |
409 | + */ | |
402 | 410 | __mingw_stdio_redirect__ |
403 | 411 | int fprintf (FILE *__stream, const char *__format, ...) |
404 | 412 | { |
@@ -457,7 +465,34 @@ _CRTIMP __cdecl __MINGW_NOTHROW int vfprintf (FILE *, const char *, __VALIST); | ||
457 | 465 | _CRTIMP __cdecl __MINGW_NOTHROW int vprintf (const char *, __VALIST); |
458 | 466 | _CRTIMP __cdecl __MINGW_NOTHROW int vsprintf (char *, const char *, __VALIST); |
459 | 467 | |
460 | -#endif | |
468 | +#endif /* !__USE_MINGW_ANSI_STDIO */ | |
469 | + | |
470 | +#if __GNUC__ && defined _ISOC99_SOURCE | |
471 | +/* Although MinGW implementations of the ISO-C99 snprintf() and | |
472 | + * vsnprintf() functions do not conflict with any implementation | |
473 | + * in MSVCRT.DLL, (because MSVCRT.DLL does not implement either), | |
474 | + * there are -Wformat attribute conflicts with the GCC built-in | |
475 | + * prototypes associated with each; by providing the following | |
476 | + * in-line function implementations, which will override GCC's | |
477 | + * built-in prototypes, we may avoid these conflicts. | |
478 | + */ | |
479 | +__mingw_stdio_redirect__ | |
480 | +int snprintf (char *__buf, size_t __len, const char *__format, ...) | |
481 | +{ | |
482 | + register int __retval; | |
483 | + __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format ); | |
484 | + __retval = __mingw_vsnprintf( __buf, __len, __format, __local_argv ); | |
485 | + __builtin_va_end( __local_argv ); | |
486 | + return __retval; | |
487 | +} | |
488 | + | |
489 | +__mingw_stdio_redirect__ | |
490 | +int vsnprintf (char *__buf, size_t __len, const char *__format, __VALIST __local_argv) | |
491 | +{ | |
492 | + return __mingw_vsnprintf( __buf, __len, __format, __local_argv ); | |
493 | +} | |
494 | +#endif /* __GNUC__ && defined _ISOC99_SOURCE */ | |
495 | + | |
461 | 496 | /* Regardless of user preference, always offer these alternative |
462 | 497 | * entry points, for direct access to the MSVCRT implementations, |
463 | 498 | * with ms_printf -Wformat checking in each case. |
@@ -10,21 +10,39 @@ | ||
10 | 10 | * standard MSVCRT function remains available, and may be invoked |
11 | 11 | * directly, using this fully qualified form of its name). |
12 | 12 | * |
13 | - * Written by Keith Marshall <keithmarshall@users.sourceforge.net> | |
13 | + * Written by Keith Marshall <keith@users.osdn.me> | |
14 | + * Copyright (C) 2008, 2019, MinGW.org Project | |
14 | 15 | * |
15 | - * This is free software. You may redistribute and/or modify it as you | |
16 | - * see fit, without restriction of copyright. | |
16 | + * This replaces earlier, substantially different implementations, | |
17 | + * originally provided as snprintf.c, and later encapsulated within | |
18 | + * gdtoa/mingw_snprintf.c: | |
17 | 19 | * |
18 | - * This software is provided "as is", in the hope that it may be useful, | |
19 | - * but WITHOUT WARRANTY OF ANY KIND, not even any implied warranty of | |
20 | - * MERCHANTABILITY, nor of FITNESS FOR ANY PARTICULAR PURPOSE. At no | |
21 | - * time will the author accept any form of liability for any damages, | |
22 | - * however caused, resulting from the use of this software. | |
20 | + * Written by Danny Smith <dannysmith@users.sourceforge.net> | |
21 | + * Copyright (C) 2002, 2003, 2007, 2008, MinGW.org Project | |
22 | + * | |
23 | + * | |
24 | + * Permission is hereby granted, free of charge, to any person obtaining a | |
25 | + * copy of this software and associated documentation files (the "Software"), | |
26 | + * to deal in the Software without restriction, including without limitation | |
27 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
28 | + * and/or sell copies of the Software, and to permit persons to whom the | |
29 | + * Software is furnished to do so, subject to the following conditions: | |
30 | + * | |
31 | + * The above copyright notice, this permission notice, and the following | |
32 | + * disclaimer shall be included in all copies or substantial portions of | |
33 | + * the Software. | |
34 | + * | |
35 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
36 | + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
37 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
38 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
39 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
40 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER | |
41 | + * DEALINGS IN THE SOFTWARE. | |
23 | 42 | * |
24 | 43 | */ |
25 | - | |
26 | -#include <stdio.h> | |
27 | 44 | #include <stdarg.h> |
45 | +#include <stddef.h> | |
28 | 46 | |
29 | 47 | #include "pformat.h" |
30 | 48 |
@@ -41,4 +59,4 @@ int __cdecl __snprintf( char *buf, size_t length, const char *fmt, ... ) | ||
41 | 59 | return retval; |
42 | 60 | } |
43 | 61 | |
44 | -/* $RCSfile$$Revision$: end of file */ | |
62 | +/* $RCSfile$: end of file */ |
@@ -10,21 +10,39 @@ | ||
10 | 10 | * standard MSVCRT function remains available, and may be invoked |
11 | 11 | * directly, using this fully qualified form of its name). |
12 | 12 | * |
13 | - * Written by Keith Marshall <keithmarshall@users.sourceforge.net> | |
13 | + * Written by Keith Marshall <keith@users.osdn.me> | |
14 | + * Copyright (C) 2008, 2019, MinGW.org Project | |
14 | 15 | * |
15 | - * This is free software. You may redistribute and/or modify it as you | |
16 | - * see fit, without restriction of copyright. | |
16 | + * This replaces earlier, substantially different implementations, | |
17 | + * originally provided as vsnprintf.c, and later encapsulated within | |
18 | + * gdtoa/mingw_snprintf.c: | |
17 | 19 | * |
18 | - * This software is provided "as is", in the hope that it may be useful, | |
19 | - * but WITHOUT WARRANTY OF ANY KIND, not even any implied warranty of | |
20 | - * MERCHANTABILITY, nor of FITNESS FOR ANY PARTICULAR PURPOSE. At no | |
21 | - * time will the author accept any form of liability for any damages, | |
22 | - * however caused, resulting from the use of this software. | |
20 | + * Written by Danny Smith <dannysmith@users.sourceforge.net> | |
21 | + * Copyright (C) 2002, 2003, 2007, 2008, MinGW.org Project | |
22 | + * | |
23 | + * | |
24 | + * Permission is hereby granted, free of charge, to any person obtaining a | |
25 | + * copy of this software and associated documentation files (the "Software"), | |
26 | + * to deal in the Software without restriction, including without limitation | |
27 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
28 | + * and/or sell copies of the Software, and to permit persons to whom the | |
29 | + * Software is furnished to do so, subject to the following conditions: | |
30 | + * | |
31 | + * The above copyright notice, this permission notice, and the following | |
32 | + * disclaimer shall be included in all copies or substantial portions of | |
33 | + * the Software. | |
34 | + * | |
35 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
36 | + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
37 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
38 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
39 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
40 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER | |
41 | + * DEALINGS IN THE SOFTWARE. | |
23 | 42 | * |
24 | 43 | */ |
25 | - | |
26 | -#include <stdio.h> | |
27 | 44 | #include <stdarg.h> |
45 | +#include <stddef.h> | |
28 | 46 | |
29 | 47 | #include "pformat.h" |
30 | 48 |
@@ -52,4 +70,4 @@ int __cdecl __vsnprintf( char *buf, size_t length, const char *fmt, va_list argv | ||
52 | 70 | return retval; |
53 | 71 | } |
54 | 72 | |
55 | -/* $RCSfile$$Revision$: end of file */ | |
73 | +/* $RCSfile$: end of file */ |
@@ -249,26 +249,31 @@ MINGW_AT_CHECK_PRINTF([[%16.0La%4d]], [1.450L, 44], [:: 0xcp-3 44::]) | ||
249 | 249 | MINGW_AT_CHECK_PRINTF([[%16.1La%4d]], [1.999L, 99], [:: 0x8.0p-2 99::]) |
250 | 250 | |
251 | 251 | |
252 | -# MINGW_AT_CHECK_SNPRINTF( FORMAT, MAXCOUNT, INITCOUNT ) | |
253 | -# ------------------------------------------------------ | |
252 | +# MINGW_AT_CHECK_SNPRINTF( FORMAT, COUNT, MAXCOUNT, INITCOUNT ) | |
253 | +# ------------------------------------------------------------- | |
254 | 254 | # Test the behaviour of the snprintf() function, with respect to |
255 | 255 | # output truncation at specified MAXCOUNT (no more than 32), when |
256 | 256 | # writing string "Sample text; sufficient buffer" subject to the |
257 | -# specified. Also supports testing the effect of "%n" counting | |
258 | -# on an internal integer variable, initialized to INITCOUNT. | |
257 | +# specified FORMAT and COUNT (concatenated to define the format | |
258 | +# string). Also supports testing the effect of "%n" counting on | |
259 | +# an internal integer variable, initialized to INITCOUNT, when | |
260 | +# COUNT is specified as "n", (with optional "hh" length modifier | |
261 | +# prefix; if this option is not to be exercised, FORMAT should | |
262 | +# be passed as "%", with COUNT as "s"). | |
259 | 263 | # |
260 | 264 | m4_define([MINGW_AT_CHECK_SNPRINTF],[dnl |
261 | -AT_SETUP([snprintf (output, $2, "$1", ...)]) | |
262 | -AT_KEYWORDS([C printf])MINGW_AT_DATA_CRLF([expout],[[$4 | |
265 | +AT_SETUP([snprintf (output, $3, "$1$2", ...)]) | |
266 | +AT_KEYWORDS([C printf])MINGW_AT_DATA_CRLF([expout],[[$5 | |
263 | 267 | ]])MINGW_AT_CHECK_RUN([[[ |
264 | 268 | #define _XOPEN_SOURCE 700 |
265 | 269 | #include <stdio.h> |
266 | 270 | int main() |
267 | -{ char output[32]; int capture = ]$3[; | |
271 | +{ char output[32]; union { int n; char hhn; } capture = {]$4[}; | |
268 | 272 | const char *sample = "Sample text; sufficient buffer"; |
269 | - int total = snprintf (output, ]$2[, "]$1[", sample, &capture); | |
270 | - snprintf (NULL, 0, "]$1[", output, &capture); | |
271 | - printf ("%s: %d required; %d captured\n", output, total, capture); | |
273 | + int total = snprintf (output, ]$3[, "]$1$2[", sample]m4_if([$2],[s],]dnl | |
274 | + [,[, &capture.$2])[); | |
275 | + snprintf (NULL, 0, "]$1$2[", output]m4_if([$2],[s],,[, &capture.$2])[); | |
276 | + printf ("%s: %d required; %d captured\n", output, total, capture.n); | |
272 | 277 | return 0; |
273 | 278 | }]]],,[expout])dnl |
274 | 279 | AT_CLEANUP |
@@ -278,20 +283,20 @@ AT_CLEANUP | ||
278 | 283 | # Tests for snprintf() with limited length internal buffer. |
279 | 284 | # |
280 | 285 | AT_BANNER([ISO-C99 snprintf() buffer length control.]) |
281 | -MINGW_AT_CHECK_SNPRINTF([[%s]],[32],[1024],dnl | |
286 | +MINGW_AT_CHECK_SNPRINTF([[%]],[s],[32],[1024],dnl | |
282 | 287 | [Sample text; sufficient buffer: 30 required; 1024 captured]) |
283 | -MINGW_AT_CHECK_SNPRINTF([[%s]],[12],[1024],dnl | |
288 | +MINGW_AT_CHECK_SNPRINTF([[%]],[s],[12],[1024],dnl | |
284 | 289 | [Sample text: 30 required; 1024 captured]) |
285 | 290 | |
286 | 291 | |
287 | 292 | # Tests for effect of "%n" output length counting. |
288 | 293 | # |
289 | 294 | AT_BANNER([ISO-C99 snprintf() intermediate output counting.]) |
290 | -MINGW_AT_CHECK_SNPRINTF([[%s%n]],[32],[1024],dnl | |
295 | +MINGW_AT_CHECK_SNPRINTF([[%s%]],[n],[32],[1024],dnl | |
291 | 296 | [Sample text; sufficient buffer: 30 required; 30 captured]) |
292 | -MINGW_AT_CHECK_SNPRINTF([[%s%n]],[12],[1024],dnl | |
297 | +MINGW_AT_CHECK_SNPRINTF([[%s%]],[n],[12],[1024],dnl | |
293 | 298 | [Sample text: 30 required; 11 captured]) |
294 | -MINGW_AT_CHECK_SNPRINTF([[%s%hhn]],[12],[1024],dnl | |
299 | +MINGW_AT_CHECK_SNPRINTF([[%s%]],[hhn],[12],[1024],dnl | |
295 | 300 | [Sample text: 30 required; 1035 captured]) |
296 | 301 | |
297 | 302 | # vim: filetype=config formatoptions=croql |