aboutsummaryrefslogtreecommitdiff
path: root/patch_reader.cc
diff options
context:
space:
mode:
authorCalder Kitagawa <ckitagawa@google.com>2018-04-24 13:54:46 +0000
committerEdward Lesmes <ehmaldonado@google.com>2021-07-23 22:09:53 +0000
commit05b1b6a1d8cfe2960959ff0ea3ecf96c4f198c54 (patch)
treec73343189a18e17ada847085bd27d0053e49d3ab /patch_reader.cc
parent451ff5de400706acdfcfdb9bf28ca6d4c0670b81 (diff)
downloadzucchini-05b1b6a1d8cfe2960959ff0ea3ecf96c4f198c54.tar.gz
[Zucchini] Update ExecutableType values.
This change has some pros and some cons: Pros: - Human readable ExecType in patch/hex dumps as the ASCII is meaningful. - Can be done at next to no cost at compile time. - Assigning new values regardless of order of appearance in the enum is more flexible. No more concern over invalidating old patches as values will be more or less permanent once this change goes in. Cons: - Checking if an ExecutableType is valid requires O(n) time where n is the number of supported Exec types using a cast. Alternatively, we could maintain a sorted list of these types in memory to check against in O(log(n)) or could use a set but this is more memory. Overall not a huge deal since we only support ~9 types but it is worth understanding the tradeoffs. - Enums don't enforce value reuse so it is possible although highly unlikely we introduce a repeated value. However, given the use of the switch case casting requiring unique values this is very unlikely. Bug: 834932 Change-Id: I7bc14ea7b4434e60bb0dafa47178fb2c2c12dc7f Reviewed-on: https://chromium-review.googlesource.com/1020446 Commit-Queue: Calder Kitagawa <ckitagawa@google.com> Reviewed-by: Samuel Huang <huangs@chromium.org> Cr-Commit-Position: refs/heads/master@{#553083} NOKEYCHECK=True GitOrigin-RevId: da4335f0d27c7fa14f6897ffeb0833d424860f7e
Diffstat (limited to 'patch_reader.cc')
-rw-r--r--patch_reader.cc3
1 files changed, 2 insertions, 1 deletions
diff --git a/patch_reader.cc b/patch_reader.cc
index 970b90c..8215405 100644
--- a/patch_reader.cc
+++ b/patch_reader.cc
@@ -4,6 +4,7 @@
#include "components/zucchini/patch_reader.h"
+#include <algorithm>
#include <type_traits>
#include <utility>
@@ -23,7 +24,7 @@ bool ParseElementMatch(BufferSource* source, ElementMatch* element_match) {
}
ExecutableType exe_type =
static_cast<ExecutableType>(element_header.exe_type);
- if (exe_type >= kNumExeType) {
+ if (CastToExecutableType(exe_type) == kExeTypeUnknown) {
LOG(ERROR) << "Invalid ExecutableType encountered.";
LOG(ERROR) << base::debug::StackTrace().ToString();
return false;