• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

The MinGW.org Windows System Libraries


Commit MetaInfo

修订版21718add2560a3103b881327bee3779b06a488ff (tree)
时间2019-07-04 05:49:42
作者Keith Marshall <keith@user...>
CommiterKeith Marshall

Log Message

Avoid built-in snprintf() prototypes; fix MinGW-Bug #39224

更改概述

差异

--- a/mingwrt/ChangeLog
+++ b/mingwrt/ChangeLog
@@ -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+
118 2019-07-01 Keith Marshall <keith@users.osdn.me>
219
320 Revert to macro implementation of "alloca()" functions.
--- a/mingwrt/include/stdio.h
+++ b/mingwrt/include/stdio.h
@@ -375,7 +375,7 @@ extern int __mingw_stdio_redirect__(vsnprintf)(char*, size_t, const char*, __VAL
375375 */
376376 extern unsigned int _mingw_output_format_control( unsigned int, unsigned int );
377377
378-#if __USE_MINGW_ANSI_STDIO
378+#if __USE_MINGW_ANSI_STDIO || defined _ISOC99_SOURCE
379379 /* User has expressed a preference for C99 conformance...
380380 */
381381 # undef __mingw_stdio_redirect__
@@ -393,12 +393,20 @@ extern unsigned int _mingw_output_format_control( unsigned int, unsigned int );
393393 */
394394 # define __mingw_stdio_redirect__ static __inline__ __cdecl __MINGW_NOTHROW
395395
396-# else
396+# else /* Neither C++ nor __GNUC__ */
397397 /* Can't use inlines; fall back on module local static stubs.
398398 */
399399 # define __mingw_stdio_redirect__ static __cdecl __MINGW_NOTHROW
400-# endif
401400
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+ */
402410 __mingw_stdio_redirect__
403411 int fprintf (FILE *__stream, const char *__format, ...)
404412 {
@@ -457,7 +465,34 @@ _CRTIMP __cdecl __MINGW_NOTHROW int vfprintf (FILE *, const char *, __VALIST);
457465 _CRTIMP __cdecl __MINGW_NOTHROW int vprintf (const char *, __VALIST);
458466 _CRTIMP __cdecl __MINGW_NOTHROW int vsprintf (char *, const char *, __VALIST);
459467
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+
461496 /* Regardless of user preference, always offer these alternative
462497 * entry points, for direct access to the MSVCRT implementations,
463498 * with ms_printf -Wformat checking in each case.
--- a/mingwrt/mingwex/stdio/snprintf.c
+++ b/mingwrt/mingwex/stdio/snprintf.c
@@ -10,21 +10,39 @@
1010 * standard MSVCRT function remains available, and may be invoked
1111 * directly, using this fully qualified form of its name).
1212 *
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
1415 *
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:
1719 *
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.
2342 *
2443 */
25-
26-#include <stdio.h>
2744 #include <stdarg.h>
45+#include <stddef.h>
2846
2947 #include "pformat.h"
3048
@@ -41,4 +59,4 @@ int __cdecl __snprintf( char *buf, size_t length, const char *fmt, ... )
4159 return retval;
4260 }
4361
44-/* $RCSfile$$Revision$: end of file */
62+/* $RCSfile$: end of file */
--- a/mingwrt/mingwex/stdio/vsnprintf.c
+++ b/mingwrt/mingwex/stdio/vsnprintf.c
@@ -10,21 +10,39 @@
1010 * standard MSVCRT function remains available, and may be invoked
1111 * directly, using this fully qualified form of its name).
1212 *
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
1415 *
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:
1719 *
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.
2342 *
2443 */
25-
26-#include <stdio.h>
2744 #include <stdarg.h>
45+#include <stddef.h>
2846
2947 #include "pformat.h"
3048
@@ -52,4 +70,4 @@ int __cdecl __vsnprintf( char *buf, size_t length, const char *fmt, va_list argv
5270 return retval;
5371 }
5472
55-/* $RCSfile$$Revision$: end of file */
73+/* $RCSfile$: end of file */
--- a/mingwrt/tests/ansiprintf.at
+++ b/mingwrt/tests/ansiprintf.at
@@ -249,26 +249,31 @@ MINGW_AT_CHECK_PRINTF([[%16.0La%4d]], [1.450L, 44], [:: 0xcp-3 44::])
249249 MINGW_AT_CHECK_PRINTF([[%16.1La%4d]], [1.999L, 99], [:: 0x8.0p-2 99::])
250250
251251
252-# MINGW_AT_CHECK_SNPRINTF( FORMAT, MAXCOUNT, INITCOUNT )
253-# ------------------------------------------------------
252+# MINGW_AT_CHECK_SNPRINTF( FORMAT, COUNT, MAXCOUNT, INITCOUNT )
253+# -------------------------------------------------------------
254254 # Test the behaviour of the snprintf() function, with respect to
255255 # output truncation at specified MAXCOUNT (no more than 32), when
256256 # 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").
259263 #
260264 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
263267 ]])MINGW_AT_CHECK_RUN([[[
264268 #define _XOPEN_SOURCE 700
265269 #include <stdio.h>
266270 int main()
267-{ char output[32]; int capture = ]$3[;
271+{ char output[32]; union { int n; char hhn; } capture = {]$4[};
268272 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);
272277 return 0;
273278 }]]],,[expout])dnl
274279 AT_CLEANUP
@@ -278,20 +283,20 @@ AT_CLEANUP
278283 # Tests for snprintf() with limited length internal buffer.
279284 #
280285 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
282287 [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
284289 [Sample text: 30 required; 1024 captured])
285290
286291
287292 # Tests for effect of "%n" output length counting.
288293 #
289294 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
291296 [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
293298 [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
295300 [Sample text: 30 required; 1035 captured])
296301
297302 # vim: filetype=config formatoptions=croql