diff options
author | Konstantin Varlamov <varconsteq@gmail.com> | 2024-01-20 23:38:02 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-20 23:38:02 -0800 |
commit | dc57752031fb14166dff2174b36c28d27d742382 (patch) | |
tree | c7a200f598952b0ea44d778bd017e1878ad2bce3 /libcxx/src | |
parent | f0c920ffb7e98adbad369c33c01e0996260c4ade (diff) | |
download | llvm-dc57752031fb14166dff2174b36c28d27d742382.zip llvm-dc57752031fb14166dff2174b36c28d27d742382.tar.gz llvm-dc57752031fb14166dff2174b36c28d27d742382.tar.bz2 |
[libc++][hardening] Categorize assertions that produce incorrect results (#77183)
Introduce a new `argument-within-domain` category that covers cases
where the given arguments make it impossible to produce a correct result
(or create a valid object in case of constructors). While the incorrect
result doesn't create an immediate problem within the library (like e.g.
a null pointer dereference would), it always indicates a logic error in
user code and is highly likely to lead to a bug in the program once the
value is used.
Diffstat (limited to 'libcxx/src')
-rw-r--r-- | libcxx/src/filesystem/operations.cpp | 5 | ||||
-rw-r--r-- | libcxx/src/include/to_chars_floating_point.h | 2 |
2 files changed, 3 insertions, 4 deletions
diff --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp index 6bee340..8a7d6cc 100644 --- a/libcxx/src/filesystem/operations.cpp +++ b/libcxx/src/filesystem/operations.cpp @@ -608,10 +608,9 @@ void __permissions(const path& p, perms prms, perm_options opts, error_code* ec) const bool resolve_symlinks = !has_opt(perm_options::nofollow); const bool add_perms = has_opt(perm_options::add); const bool remove_perms = has_opt(perm_options::remove); - _LIBCPP_ASSERT_UNCATEGORIZED( + _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( (add_perms + remove_perms + has_opt(perm_options::replace)) == 1, - "One and only one of the perm_options constants replace, add, or remove " - "is present in opts"); + "One and only one of the perm_options constants 'replace', 'add', or 'remove' must be present in opts"); bool set_sym_perms = false; prms &= perms::mask; diff --git a/libcxx/src/include/to_chars_floating_point.h b/libcxx/src/include/to_chars_floating_point.h index e4715d1..01c2618 100644 --- a/libcxx/src/include/to_chars_floating_point.h +++ b/libcxx/src/include/to_chars_floating_point.h @@ -994,7 +994,7 @@ to_chars_result _Floating_to_chars( if constexpr (_Overload == _Floating_to_chars_overload::_Plain) { _LIBCPP_ASSERT_INTERNAL(_Fmt == chars_format{}, ""); // plain overload must pass chars_format{} internally } else { - _LIBCPP_ASSERT_UNCATEGORIZED(_Fmt == chars_format::general || _Fmt == chars_format::scientific + _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(_Fmt == chars_format::general || _Fmt == chars_format::scientific || _Fmt == chars_format::fixed || _Fmt == chars_format::hex, "invalid format in to_chars()"); } |