Skip to content

Conversation

@Prabhuk
Copy link
Contributor

@Prabhuk Prabhuk commented Mar 4, 2025

_LIBCPP_DIAGNOSE_NULLPTR annotation was introduced to catch the
misuse of APIs that take a pointer to a null-terminated string.
Adding the missing annotation to one of the APIs.

`_LIBCPP_DIAGNOSE_NULLPTR` annotation was introduced to catch the
misuse of APIs that take a pointer to a null-terminated string.
Adding the missing annotation to one of the APIs.
@Prabhuk Prabhuk requested a review from a team as a code owner March 4, 2025 23:27
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Mar 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 4, 2025

@llvm/pr-subscribers-libcxx

Author: Prabhuk (Prabhuk)

Changes

_LIBCPP_DIAGNOSE_NULLPTR annotation was introduced to catch the
misuse of APIs that take a pointer to a null-terminated string.
Adding the missing annotation to one of the APIs.


Full diff: https://github.com/llvm/llvm-project/pull/129798.diff

1 Files Affected:

  • (modified) libcxx/include/string (+1-1)
diff --git a/libcxx/include/string b/libcxx/include/string
index 419e3eee6746e..470531be0cf41 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -1054,7 +1054,7 @@ public:
   basic_string(nullptr_t) = delete;
 #  endif
 
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, size_type __n) {
+  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* _LIBCPP_DIAGNOSE_NULLPTR __s, size_type __n) {
     _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
     __init(__s, __n);
   }

@Prabhuk Prabhuk marked this pull request as draft March 4, 2025 23:29
@Prabhuk Prabhuk removed the request for review from a team March 4, 2025 23:29
@github-actions
Copy link

github-actions bot commented Mar 4, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff e697c99b63224069daa3814f536a69fecab8cd4e 6669c473d256979b8dd882e4726ccc23de705844 --extensions  -- libcxx/include/string
View the diff from clang-format here.
diff --git a/libcxx/include/string b/libcxx/include/string
index 470531be0c..76032670a6 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -1054,7 +1054,8 @@ public:
   basic_string(nullptr_t) = delete;
 #  endif
 
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* _LIBCPP_DIAGNOSE_NULLPTR __s, size_type __n) {
+  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
+  basic_string(const _CharT* _LIBCPP_DIAGNOSE_NULLPTR __s, size_type __n) {
     _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
     __init(__s, __n);
   }

Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect. You are allowed to pass a nullptr if the size is zero.

@Prabhuk
Copy link
Contributor Author

Prabhuk commented Mar 4, 2025

This is incorrect. You are allowed to pass a nullptr if the size is zero.

Thank you @philnik777
I just noticed your comment on the PR that introduced the annotation. I'll close this one and will work on the suggestion provided there.

@Prabhuk Prabhuk closed this Mar 4, 2025
@Prabhuk Prabhuk deleted the fix_libcpp branch May 14, 2025 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants