Skip to content

Don't pass null to memcpy and simplify debug assert - #2253

Open
anuraaga wants to merge 3 commits into
cel-expr:masterfrom
anuraaga:fix-empty-byte-string-copy
Open

Don't pass null to memcpy and simplify debug assert#2253
anuraaga wants to merge 3 commits into
cel-expr:masterfrom
anuraaga:fix-empty-byte-string-copy

Conversation

@anuraaga

@anuraaga anuraaga commented Sep 8, 2026

Copy link
Copy Markdown

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 memcpy always 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

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>
Comment thread common/value.h
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);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Compares unsigned long to int triggering signedness warning. Trivial to just switch to a boolean check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant