Don't pass null to memcpy and simplify debug assert - #2253
Open
anuraaga wants to merge 3 commits into
Open
Conversation
Skip empty copies in ByteString::SetSmall so default-constructed string views do not trigger nonnull-attribute diagnostics from libc memcpy declarations. Checking at the copy also covers borrowed and external string construction. Add a regression test using the existing heap and arena allocator cases. C2y permits zero-length operations on null pointers, but existing libc headers can still annotate memcpy arguments as unconditionally nonnull. Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
Use the non-empty precondition directly instead of comparing size_t with an int literal through Abseil's templated comparison helper. This avoids -Wsign-compare in debug builds without narrowing the qualifier count. Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
anuraaga
commented
Sep 8, 2026
| const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, | ||
| google::protobuf::MessageFactory* absl_nonnull message_factory, | ||
| google::protobuf::Arena* absl_nonnull arena) const { | ||
| ABSL_DCHECK_GT(qualifiers.size(), 0); |
Author
There was a problem hiding this comment.
Compares unsigned long to int triggering signedness warning. Trivial to just switch to a boolean check
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Envoy has had some very long-standing patches for cel-cpp that get triggered by its stricter build that enables address sanitization and
-Wextra. AFAICT these small issues are all that prevents Envoy from updating to a latest upstream cel-cpp dependency (the other parts of the patch are already present here).https://github.com/envoyproxy/bazel-registry/blob/b6e15c00b1c0493cd194b1b248c562bd8bc46648/modules/cel-cpp/0.14.0.envoy/patches/cel-cpp.patch
A
memcpyalways needs to have non-null pointers, at least until C20 becomes mainstream, which is typically accomplished by a length check. While downstream effects are unlikely, it seems theoretically possible for SetSmall to be inlined before a nullptr check that gets erased, so a highly theoretical bug that triggers sanitizers.Envoy being able to update would unblock work to support Windows @yanavlasov is working on. I suspect being able to use upstream cel-cpp would make @phlax happy too