aboutsummaryrefslogtreecommitdiff
path: root/types_test.cpp
diff options
context:
space:
mode:
authorShaju Mathew <shaju@google.com>2023-09-20 19:32:39 -0700
committerShaju Mathew <shaju@google.com>2023-09-21 16:29:31 -0700
commitf4e573399592c89b9a35451cb2f39fc6a6e0c6f2 (patch)
tree7c22c4e4190e9a86865f3c1f985fcd6b81724909 /types_test.cpp
parentf78ea1a444c2220c831095ef11d2173220e4b0ae (diff)
downloadadb-f4e573399592c89b9a35451cb2f39fc6a6e0c6f2.tar.gz
Enforcing static invariants to prevent failures arising from layout
disparity. Bug: 301330806 Test: see below: - compilation (static_assert()) - Run adb_test, adbd_test (for regression) Change-Id: Icd2bb35c8eedfe657b26b77e183df7bf05c13b31
Diffstat (limited to 'types_test.cpp')
-rw-r--r--types_test.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/types_test.cpp b/types_test.cpp
index 5cb21336..5a446a8c 100644
--- a/types_test.cpp
+++ b/types_test.cpp
@@ -19,6 +19,7 @@
#include <gtest/gtest.h>
#include <memory>
+#include <type_traits>
#include <utility>
#include "fdevent/fdevent_test.h"
@@ -30,7 +31,11 @@ static IOVector::block_type create_block(const std::string& string) {
static IOVector::block_type create_block(char value, size_t len) {
auto block = IOVector::block_type();
block.resize(len);
+
+ static_assert(std::is_standard_layout<struct Block>());
+ static_assert(std::is_standard_layout<struct IOVector>());
memset(&(block)[0], value, len);
+
return block;
}