File chromium-98-EnumTable-crash.patch of Package chromium-ffmpeg-extra (Revision acf13cd4d3b182c723d1231bb1ce7ca6)
Currently displaying revision acf13cd4d3b182c723d1231bb1ce7ca6 , Show latest
77
1
diff --git a/components/cast_channel/enum_table.h b/components/cast_channel/enum_table.h
2
index 842553a..89de703 100644
3
--- a/components/cast_channel/enum_table.h
4
+++ b/components/cast_channel/enum_table.h
5
6
#include <cstdint>
7
#include <cstring>
8
#include <ostream>
9
+#include <vector>
10
11
#include "base/check_op.h"
12
#include "base/notreached.h"
13
14
inline constexpr GenericEnumTableEntry(int32_t value);
15
inline constexpr GenericEnumTableEntry(int32_t value, base::StringPiece str);
16
17
- GenericEnumTableEntry(const GenericEnumTableEntry&) = delete;
18
GenericEnumTableEntry& operator=(const GenericEnumTableEntry&) = delete;
19
20
private:
21
22
constexpr Entry(E value, base::StringPiece str)
23
: GenericEnumTableEntry(static_cast<int32_t>(value), str) {}
24
25
- Entry(const Entry&) = delete;
26
Entry& operator=(const Entry&) = delete;
27
};
28
29
30
if (is_sorted_) {
31
const std::size_t index = static_cast<std::size_t>(value);
32
if (ANALYZER_ASSUME_TRUE(index < data_.size())) {
33
- const auto& entry = data_.begin()[index];
34
+ const auto& entry = data_[index];
35
if (ANALYZER_ASSUME_TRUE(entry.has_str()))
36
return entry.str();
37
}
38
return absl::nullopt;
39
}
40
return GenericEnumTableEntry::FindByValue(
41
- reinterpret_cast<const GenericEnumTableEntry*>(data_.begin()),
42
- data_.size(), static_cast<int32_t>(value));
43
+ &data_[0], data_.size(), static_cast<int32_t>(value));
44
}
45
46
// This overload of GetString is designed for cases where the argument is a
47
48
// enum value directly.
49
absl::optional<E> GetEnum(base::StringPiece str) const {
50
auto* entry = GenericEnumTableEntry::FindByString(
51
- reinterpret_cast<const GenericEnumTableEntry*>(data_.begin()),
52
- data_.size(), str);
53
+ &data_[0], data_.size(), str);
54
return entry ? static_cast<E>(entry->value) : absl::optional<E>();
55
}
56
57
58
// Align the data on a cache line boundary.
59
alignas(64)
60
#endif
61
- std::initializer_list<Entry> data_;
62
+ const std::vector<Entry> data_;
63
bool is_sorted_;
64
65
constexpr EnumTable(std::initializer_list<Entry> data, bool is_sorted)
66
67
68
for (std::size_t i = 0; i < data.size(); i++) {
69
for (std::size_t j = i + 1; j < data.size(); j++) {
70
- const Entry& ei = data.begin()[i];
71
- const Entry& ej = data.begin()[j];
72
+ const Entry& ei = data[i];
73
+ const Entry& ej = data[j];
74
DCHECK(ei.value != ej.value)
75
<< "Found duplicate enum values at indices " << i << " and " << j;
76
DCHECK(!(ei.has_str() && ej.has_str() && ei.str() == ej.str()))
77