-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[libc++] Fix money_get::do_get with huge input
#126273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
61775dc
[libc++] Fix money_get::do_get with huge input
frederick-vs-ja 2849685
Merge branch 'main' into get-huge-money
frederick-vs-ja 119ed43
Address @mordante's review comments on the test
frederick-vs-ja bee1af8
Merge branch 'main' into get-huge-money
frederick-vs-ja a1627af
Merge branch 'main' into get-huge-money
frederick-vs-ja ce97bad
Drop changes in frozen C++03 headers
frederick-vs-ja 06afe4e
Merge branch 'main' into get-huge-money
frederick-vs-ja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
...gory.monetary/locale.money.get/locale.money.get.members/get_long_double_overlong.pass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // <locale> | ||
|
|
||
| // class money_get<charT, InputIterator> | ||
|
|
||
| // iter_type get(iter_type b, iter_type e, bool intl, ios_base& iob, | ||
| // ios_base::iostate& err, long double& v) const; | ||
|
|
||
| // Ensure that money_get::do_get correct works when the input doesn't fit into the stack buffer | ||
| // (100 characters currently). | ||
|
|
||
| // XFAIL: FROZEN-CXX03-HEADERS-FIXME | ||
|
|
||
| #include <cassert> | ||
| #include <cstddef> | ||
| #include <ios> | ||
| #include <locale> | ||
| #include <streambuf> | ||
| #include <string> | ||
|
|
||
| #include "make_string.h" | ||
| #include "test_macros.h" | ||
| #include "test_iterators.h" | ||
|
|
||
| template <class CharT> | ||
| class my_basic_facet : public std::money_get<CharT, cpp17_input_iterator<const CharT*> > { | ||
| private: | ||
| typedef std::money_get<CharT, cpp17_input_iterator<const CharT*> > Base; | ||
|
|
||
| public: | ||
| explicit my_basic_facet(std::size_t refs = 0) : Base(refs) {} | ||
| }; | ||
|
|
||
| template <class CharT> | ||
| void test() { | ||
| struct digit_result_case { | ||
| std::size_t digit; | ||
| long double result; | ||
frederick-vs-ja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
| const digit_result_case digit_result_cases[] = { | ||
| {60, 2.0E60L}, {120, 2.0E120L}, {180, 2.0E180L}, {240, 2.0E240L}, {300, 2.0E300L}}; | ||
|
|
||
| std::ios ios(0); | ||
| { | ||
| const my_basic_facet<CharT> f(1); | ||
| for (std::size_t i = 0; i != sizeof(digit_result_cases) / sizeof(digit_result_cases[0]); ++i) { | ||
| { | ||
| std::basic_string<CharT> v = MAKE_STRING(CharT, "2"); | ||
| v.append(digit_result_cases[i].digit, static_cast<CharT>('0')); | ||
|
|
||
| typedef cpp17_input_iterator<const CharT*> I; | ||
| long double ex; | ||
| std::ios_base::iostate err = std::ios_base::goodbit; | ||
| I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); | ||
| assert(base(iter) == v.data() + v.size()); | ||
| assert(err == std::ios_base::eofbit); | ||
| assert(ex == digit_result_cases[i].result); | ||
| } | ||
| { | ||
| std::basic_string<CharT> v = MAKE_STRING(CharT, "-2"); | ||
| v.append(digit_result_cases[i].digit, static_cast<CharT>('0')); | ||
|
|
||
| typedef cpp17_input_iterator<const CharT*> I; | ||
| long double ex; | ||
| std::ios_base::iostate err = std::ios_base::goodbit; | ||
| I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); | ||
| assert(base(iter) == v.data() + v.size()); | ||
| assert(err == std::ios_base::eofbit); | ||
| assert(ex == -digit_result_cases[i].result); | ||
| } | ||
| { | ||
| std::basic_string<CharT> v = MAKE_STRING(CharT, "0."); | ||
| v.append(digit_result_cases[i].digit, static_cast<CharT>('0')); | ||
| v += MAKE_CSTRING(CharT, "2"); | ||
|
|
||
| typedef cpp17_input_iterator<const CharT*> I; | ||
| long double ex; | ||
| std::ios_base::iostate err = std::ios_base::goodbit; | ||
| I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); | ||
| assert(base(iter) == v.data() + 1); | ||
| assert(err == std::ios_base::goodbit); | ||
| assert(ex == 0.0L); | ||
| } | ||
| { | ||
| std::basic_string<CharT> v = MAKE_STRING(CharT, "-0."); | ||
| v.append(digit_result_cases[i].digit, static_cast<CharT>('0')); | ||
| v += MAKE_CSTRING(CharT, "2"); | ||
|
|
||
| typedef cpp17_input_iterator<const CharT*> I; | ||
| long double ex; | ||
| std::ios_base::iostate err = std::ios_base::goodbit; | ||
| I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); | ||
| assert(base(iter) == v.data() + 2); | ||
| assert(err == std::ios_base::goodbit); | ||
| assert(ex == 0.0L); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| int main(int, char**) { | ||
| test<char>(); | ||
| #ifndef TEST_HAS_NO_WIDE_CHARACTERS | ||
| test<wchar_t>(); | ||
| #endif | ||
|
|
||
| return 0; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.