[libcxx-commits] [libcxx] [libc++][hardening] Add `_LIBCPP_ASSERT_NON_NULL` to check for null pointers (PR #71428)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Nov 6 23:03:15 PST 2023


================
@@ -235,7 +235,7 @@ recursive_directory_iterator::recursive_directory_iterator(
 }
 
 void recursive_directory_iterator::__pop(error_code* ec) {
-  _LIBCPP_ASSERT_UNCATEGORIZED(__imp_, "Popping the end iterator");
+  _LIBCPP_ASSERT_NON_NULL(__imp_, "Popping the end iterator");
----------------
ldionne wrote:

This instance of `_LIBCPP_ASSERT_NON_NULL` makes me wonder whether we want to have `_LIBCPP_ASSERT_NON_NULL(boolean-expr, message)` or `_LIBCPP_ASSERT_NON_NULL(ptr, message)`. All the other ones are of the form `_LIBCPP_ASSERT_NON_NULL(ptr != nullptr, msg)` but this one is `_LIBCPP_ASSERT_NON_NULL(ptr, msg)`.

If we decide that we want to keep it like all the other assertion macros and keep `_LIBCPP_ASSERT_NON_NULL(boolean-expr, msg)`, then I think I would change these few instances to `_LIBCPP_ASSERT_NON_NULL(__imp_ != nullptr, "Popping the end iterator");`.

https://github.com/llvm/llvm-project/pull/71428


More information about the libcxx-commits mailing list