Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions stl/inc/chrono
Original file line number Diff line number Diff line change
Expand Up @@ -1725,9 +1725,15 @@ namespace chrono {

_EXPORT_STD class _NODISCARD nonexistent_local_time : public runtime_error {
public:
#if _HAS_EXCEPTIONS
template <class _Duration>
nonexistent_local_time(const local_time<_Duration>& _Tp, const local_info& _Info)
: runtime_error(_Make_string(_Tp, _Info)) {}
#else // ^^^ _HAS_EXCEPTIONS / !_HAS_EXCEPTIONS vvv
template <class _Duration>
nonexistent_local_time(const local_time<_Duration>&, const local_info&)
: runtime_error("nonexistent local time") {}
#endif // ^^^ !_HAS_EXCEPTIONS ^^^

private:
template <class _Duration>
Expand All @@ -1741,9 +1747,14 @@ namespace chrono {

_EXPORT_STD class _NODISCARD ambiguous_local_time : public runtime_error {
public:
#if _HAS_EXCEPTIONS
template <class _Duration>
ambiguous_local_time(const local_time<_Duration>& _Tp, const local_info& _Info)
: runtime_error(_Make_string(_Tp, _Info)) {}
#else // ^^^ _HAS_EXCEPTIONS / !_HAS_EXCEPTIONS vvv
template <class _Duration>
ambiguous_local_time(const local_time<_Duration>&, const local_info&) : runtime_error("ambiguous local time") {}
#endif // ^^^ !_HAS_EXCEPTIONS ^^^

private:
template <class _Duration>
Expand Down
6 changes: 6 additions & 0 deletions stl/inc/system_error
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,16 @@ private:
}

protected:
#if _HAS_EXCEPTIONS
_System_error(error_code _Errcode) : runtime_error(_Errcode.message()), _Mycode(_Errcode) {}

_System_error(error_code _Errcode, const string& _Message)
: runtime_error(_Makestr(_Errcode, _Message)), _Mycode(_Errcode) {}
#else // ^^^ _HAS_EXCEPTIONS / !_HAS_EXCEPTIONS vvv
_System_error(error_code _Errcode) : runtime_error("system error"), _Mycode(_Errcode) {}

_System_error(error_code _Errcode, const string&) : runtime_error("system error"), _Mycode(_Errcode) {}
#endif // ^^^ !_HAS_EXCEPTIONS ^^^

error_code _Mycode; // the stored error code
};
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ tests\GH_004930_char_traits_user_specialization
tests\GH_005090_stl_hardening
tests\GH_005204_regex_collating_ranges
tests\GH_005244_regex_escape_sequences
tests\GH_005276_system_error_heap_use_after_free
tests\GH_005315_destructor_tombstones
tests\LWG2381_num_get_floating_point
tests\LWG2597_complex_branch_cut
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\usual_20_matrix.lst
RUNALL_CROSSLIST
* PM_CL="/D_HAS_EXCEPTIONS=0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <cassert>
#include <chrono>
#include <string>
#include <string_view>
#include <system_error>
using namespace std;
using namespace chrono;

// GH-5276 <system_error>: heap-use-after-free for _HAS_EXCEPTIONS=0
int main() {
const string str{"abc"};
const error_code ec{2, system_category()};
{
system_error syserr1{ec};
assert(syserr1.what() == "system error"sv);
}
{
system_error syserr2{ec, str};
assert(syserr2.what() == "system error"sv);
}
{
system_error syserr3{ec, "meow"};
assert(syserr3.what() == "system error"sv);
}
{
system_error syserr4{2, system_category()};
assert(syserr4.what() == "system error"sv);
}
{
system_error syserr5{2, system_category(), str};
assert(syserr5.what() == "system error"sv);
}
{
system_error syserr6{2, system_category(), "meow"};
assert(syserr6.what() == "system error"sv);
}

{
ambiguous_local_time alt{local_seconds{}, local_info{}};
assert(alt.what() == "ambiguous local time"sv);
}
{
nonexistent_local_time nlt{local_seconds{}, local_info{}};
assert(nlt.what() == "nonexistent local time"sv);
}
}