• 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

修订版b9742c6cc57e4916d96d4e7bbf3c49d2ea4d56f1 (tree)
时间2020-03-05 07:55:56
作者Keith Marshall <keith@user...>
CommiterKeith Marshall

Log Message

Disallow surrogates as printf() radix and grouping characters.

更改概述

差异

--- a/mingwrt/ChangeLog
+++ b/mingwrt/ChangeLog
@@ -1,5 +1,15 @@
11 2020-03-04 Keith Marshall <keith@users.osdn.me>
22
3+ Disallow surrogates as printf() radix and grouping characters.
4+
5+ * mingwex/stdio/pformat.c (__pformat_emit_digit)
6+ [(c == '.') && ((rpchr & 0xF800) == 0xD800)]: Radix point requires a
7+ surrogate pair, for representation as UTF-16LE; decline to use it.
8+ (__pformat_enable_thousands_grouping) [(tc & 0xF800) == 0xD800]:
9+ Likewise, for thousands group separator.
10+
11+2020-03-04 Keith Marshall <keith@users.osdn.me>
12+
313 Reimplement wcstof(), and wcstold() functions.
414
515 * mingwex/wcstofp.c: New file; it implements...
--- a/mingwrt/mingwex/stdio/pformat.c
+++ b/mingwrt/mingwex/stdio/pformat.c
@@ -7,8 +7,8 @@
77 * generally to C99 and SUSv3/POSIX specifications, with extensions
88 * to support Microsoft's non-standard format specifications.
99 *
10- * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
11- * Copyright (C) 2008, 2009, 2011, 2014-2018, MinGW.org Project
10+ * Written by Keith Marshall <keith@users.osdn.me>
11+ * Copyright (C) 2008, 2009, 2011, 2014-2018, 2020, MinGW.org Project
1212 *
1313 *
1414 * Permission is hereby granted, free of charge, to any person obtaining a
@@ -494,7 +494,23 @@ int __pformat_enable_thousands_grouping( __pformat_t *stream )
494494 memset( &state, 0, sizeof( state ) );
495495 if( (*stream->grouping < CHAR_MAX)
496496 && ((len = mbrtowc( &ts, localeconv()->thousands_sep, 16, &state )) > 0) )
497- stream->tschr = ts;
497+ {
498+ /* We have a potentially viable grouping character, but we
499+ * will accept it only if it can be represented as a single
500+ * wchar_t UTF-16LE code point...
501+ */
502+ if( (ts & 0xF800) == 0xD800 )
503+ {
504+ /* ...but anything matching this, (i.e. it is in the range
505+ * 0xD800..0xDFFF), represents one element of a surrogate
506+ * pair; we reject this.
507+ */
508+ ts = (wchar_t)(0);
509+ len = -1;
510+ }
511+ else
512+ stream->tschr = ts;
513+ }
498514 stream->tslen = len;
499515 }
500516 /* Check that we've established a usable grouping strategy, (but
@@ -612,11 +628,22 @@ void __pformat_emit_digit( int c, __pformat_t *stream )
612628 /* Fetch and convert the localised radix point representation...
613629 */
614630 if( (len = mbrtowc( &rpchr, localeconv()->decimal_point, 16, &state )) > 0 )
615- /*
616- * and store it, if valid.
631+ {
632+ /* We require the representation to be a single wchar_t
633+ * UTF-16LE code point...
617634 */
618- stream->rpchr = rpchr;
635+ if( (rpchr & 0xF800) == 0xD800 )
636+ /*
637+ * ...but this is one element of a surrogate pair, which
638+ * we do not accept.
639+ */
640+ len = -1;
619641
642+ else
643+ /* or store it, if valid.
644+ */
645+ stream->rpchr = rpchr;
646+ }
620647 /* In any case, store the reported effective multibyte length,
621648 * (or the error flag), marking initialisation as `done'.
622649 */