Attention needed from Siddhartha S
Arthur Sonzogni has uploaded the change for review![Open in Gerrit]()
Arthur Sonzogni would like Siddhartha S to review this change.
Commit message
Replace memset with aggregate initialization in services
Using `memset` to zero-initialize C++ objects is sometimes unsafe for
non-trivial types. It bypasses C++ constructors and destructors, which
can break class invariant. Additionally, providing an incorrect size to
`memset` can result in out-of-bounds memory writes.
This patch replaces these calls with aggregate initialization
(`instance = {}`), which correctly and safely initializes members
without bypassing C++ language semantics.
The bulk of this patch was generated by a script using tree-sitter:
https://paste.googleplex.com/5357187081437184?raw
The script was mainly generated by gemini.
Following the automated pass, Gemini was prompted to refine the changes
by:
- Reverting changes for most structs containing unions.
- Reverting changes where nearby comments indicated `memset` was
intentional.
- Moving initializations directly to the declaration where possible.
Reviewer Note: This refactoring is intended to be a behavior-preserving
modernization. However, `memset` and aggregate initialization are not
strictly equivalent. For instance `memset` zeroes the entire memory
block, including padding, while aggregate initialization only
initializes specified members. Please review carefully for any code that
might have implicitly relied on the non-standard behavior of zeroing the
entire object memory. I did my past to spot such cases, but there may be
some edge cases that require a review.
This CL was uploaded by git cl split.
R=ss...@chromium.org
Bug: 435317390
Change-Id: Ia7b8a0994bc6d55862e91e2f5ddbca530e42c2ac
Change diff
diff --git a/services/tracing/public/cpp/system_tracing_service.cc b/services/tracing/public/cpp/system_tracing_service.cc
index b2374bf1..3edb220 100644
--- a/services/tracing/public/cpp/system_tracing_service.cc
+++ b/services/tracing/public/cpp/system_tracing_service.cc
@@ -75,7 +75,7 @@
}
struct sockaddr_un saddr;
- UNSAFE_TODO(memset(&saddr, 0, sizeof(saddr)));
+ saddr = {};
UNSAFE_TODO(memcpy(saddr.sun_path, producer_sock_name.data(),
producer_sock_name.size()));
saddr.sun_family = AF_UNIX;
Change information
Files:
- M services/tracing/public/cpp/system_tracing_service.cc
Change size: XS
Delta: 1 file changed, 1 insertion(+), 1 deletion(-)
Open in GerritRelated details
Attention is currently required from:
Gerrit-MessageType: newchange
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Ia7b8a0994bc6d55862e91e2f5ddbca530e42c2ac
Gerrit-Change-Number: 6875522
Gerrit-PatchSet: 1