MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / ValidateLegacy64

Function ValidateLegacy64

src/DartsDict.cpp:84–97  ·  view source on GitHub ↗

Mirror of Darts::DoubleArray::validate(); checks root sanity, offset bounds, and leaf value bounds to catch malformed legacy files before any traversal.

Source from the content-addressed store, hash-verified

82// Mirror of Darts::DoubleArray::validate(); checks root sanity, offset bounds,
83// and leaf value bounds to catch malformed legacy files before any traversal.
84bool ValidateLegacy64(const LegacyUnit64* arr, size_t numUnits, int maxValueLimit) {
85 if (numUnits == 0) return false;
86 if (arr[0].label() != 0 || arr[0].has_leaf() || arr[0].offset() == 0) return false;
87 if (((static_cast<size_t>(arr[0].offset())) | 0xFFu) >= numUnits) return false;
88 for (size_t i = 1; i < numUnits; ++i) {
89 uint64_t lbl = arr[i].label();
90 if (lbl <= 0xFF) {
91 if (((i ^ static_cast<size_t>(arr[i].offset())) | 0xFFu) >= numUnits) return false;
92 } else if (maxValueLimit >= 0) {
93 if (arr[i].value() >= maxValueLimit) return false;
94 }
95 }
96 return true;
97}
98
99} // namespace
100

Callers 2

NewFromFileMethod · 0.85
NewFromBufferMethod · 0.85

Calls 4

labelMethod · 0.45
has_leafMethod · 0.45
offsetMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected