The MinGW.org Windows System Libraries
修订版 | b9742c6cc57e4916d96d4e7bbf3c49d2ea4d56f1 (tree) |
---|---|
时间 | 2020-03-05 07:55:56 |
作者 | Keith Marshall <keith@user...> |
Commiter | Keith Marshall |
Disallow surrogates as printf() radix and grouping characters.
@@ -1,5 +1,15 @@ | ||
1 | 1 | 2020-03-04 Keith Marshall <keith@users.osdn.me> |
2 | 2 | |
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 | + | |
3 | 13 | Reimplement wcstof(), and wcstold() functions. |
4 | 14 | |
5 | 15 | * mingwex/wcstofp.c: New file; it implements... |
@@ -7,8 +7,8 @@ | ||
7 | 7 | * generally to C99 and SUSv3/POSIX specifications, with extensions |
8 | 8 | * to support Microsoft's non-standard format specifications. |
9 | 9 | * |
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 | |
12 | 12 | * |
13 | 13 | * |
14 | 14 | * Permission is hereby granted, free of charge, to any person obtaining a |
@@ -494,7 +494,23 @@ int __pformat_enable_thousands_grouping( __pformat_t *stream ) | ||
494 | 494 | memset( &state, 0, sizeof( state ) ); |
495 | 495 | if( (*stream->grouping < CHAR_MAX) |
496 | 496 | && ((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 | + } | |
498 | 514 | stream->tslen = len; |
499 | 515 | } |
500 | 516 | /* Check that we've established a usable grouping strategy, (but |
@@ -612,11 +628,22 @@ void __pformat_emit_digit( int c, __pformat_t *stream ) | ||
612 | 628 | /* Fetch and convert the localised radix point representation... |
613 | 629 | */ |
614 | 630 | 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... | |
617 | 634 | */ |
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; | |
619 | 641 | |
642 | + else | |
643 | + /* or store it, if valid. | |
644 | + */ | |
645 | + stream->rpchr = rpchr; | |
646 | + } | |
620 | 647 | /* In any case, store the reported effective multibyte length, |
621 | 648 | * (or the error flag), marking initialisation as `done'. |
622 | 649 | */ |