Commit fec392cd for tesseract
commit fec392cdc84cebe9acba61a878a5b8a295e711af
Author: Stefan Weil <sw@weilnetz.de>
Date: Thu Oct 8 14:15:46 2026 +0200
Refactor MakeAdaptedClassRecord implementation
Refactor MakeAdaptedClassRecord to use a local layout variable instead of a pointer to ADAPT_CLASS_STRUCT.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
diff --git a/unittest/adaptive_test.cc b/unittest/adaptive_test.cc
index a0f6df76..c57436bd 100644
--- a/unittest/adaptive_test.cc
+++ b/unittest/adaptive_test.cc
@@ -37,9 +37,10 @@ namespace {
std::vector<char> MakeAdaptedClassRecord(int32_t num_temp_protos, int32_t num_configs,
uint8_t fill) {
std::vector<char> data(sizeof(ADAPT_CLASS_STRUCT), static_cast<char>(fill));
- ADAPT_CLASS_STRUCT *s = reinterpret_cast<ADAPT_CLASS_STRUCT *>(data.data());
- s->NumPermConfigs = 0;
- s->MaxNumTimesSeen = 0;
+ ADAPT_CLASS_STRUCT layout;
+ const auto *base = reinterpret_cast<const char *>(&layout);
+ data[reinterpret_cast<const char *>(&layout.NumPermConfigs) - base] = 0;
+ data[reinterpret_cast<const char *>(&layout.MaxNumTimesSeen) - base] = 0;
// PermProtos and PermConfigs are reallocated by ReadAdaptedClass, so their
// initial (file) values are irrelevant; leave them as the fill value.
auto append = [&data](const void *p, size_t n) {