@@ -140,11 +140,8 @@ class MinidumpFile : public Binary {
140
140
size_t Stride;
141
141
};
142
142
143
-
144
- // / Class the provides an iterator over the memory64 memory ranges. Ranges
145
- // / are not validated before hand, and so any increment operation could fail.
146
- // / For this reason, the iterator in it's initial state points to a default
147
- // / initialized std::pair and should be advanced before dereferencing.
143
+ // / Class the provides an iterator over the memory64 memory ranges. Only the
144
+ // / the first descriptor is validated as readable beforehand.
148
145
class Memory64Iterator {
149
146
public:
150
147
static Memory64Iterator
@@ -159,18 +156,18 @@ class MinidumpFile : public Binary {
159
156
std::pair<minidump::MemoryDescriptor_64, ArrayRef<uint8_t >> Current;
160
157
161
158
bool operator ==(const Memory64Iterator &R) const {
162
- return isEnd == R.isEnd ;
159
+ return IsEnd == R.IsEnd ;
163
160
}
164
161
165
162
bool operator !=(const Memory64Iterator &R) const { return !(*this == R); }
166
163
167
164
const std::pair<minidump::MemoryDescriptor_64, ArrayRef<uint8_t >> &
168
- operator *() const {
165
+ operator *() {
169
166
return Current;
170
167
}
171
168
172
169
const std::pair<minidump::MemoryDescriptor_64, ArrayRef<uint8_t >> *
173
- operator ->() const {
170
+ operator &() {
174
171
return &Current;
175
172
}
176
173
@@ -190,29 +187,37 @@ class MinidumpFile : public Binary {
190
187
191
188
ArrayRef<uint8_t > Content = Storage.slice (RVA, Descriptor.DataSize );
192
189
Current = std::make_pair (Descriptor, Content);
193
- RVA += Descriptor.DataSize ;
194
190
Index++;
191
+ RVA += Descriptor.DataSize ;
195
192
if (Index >= Descriptors.size ())
196
- isEnd = true ;
193
+ IsEnd = true ;
197
194
return Error::success ();
198
195
}
199
196
200
197
private:
198
+ // This constructor will only happen after a validation check to see
199
+ // if the first descriptor is readable.
201
200
Memory64Iterator (ArrayRef<uint8_t > Storage,
202
201
ArrayRef<minidump::MemoryDescriptor_64> Descriptors,
203
202
uint64_t BaseRVA)
204
203
: RVA(BaseRVA), Storage(Storage), Descriptors(Descriptors),
205
- isEnd (false ) {}
204
+ IsEnd (false ) {
205
+ assert (Descriptors.size () > 0 );
206
+ assert (Storage.size () >= BaseRVA + Descriptors.front ().DataSize );
207
+ Current =
208
+ std::make_pair (Descriptors.front (),
209
+ Storage.slice (BaseRVA, Descriptors.front ().DataSize ));
210
+ }
206
211
207
212
Memory64Iterator ()
208
213
: RVA(0 ), Storage(ArrayRef<uint8_t >()),
209
- Descriptors(ArrayRef<minidump::MemoryDescriptor_64>()), isEnd (true ) {}
214
+ Descriptors(ArrayRef<minidump::MemoryDescriptor_64>()), IsEnd (true ) {}
210
215
211
216
size_t Index = 0 ;
212
217
uint64_t RVA;
213
218
ArrayRef<uint8_t > Storage;
214
219
ArrayRef<minidump::MemoryDescriptor_64> Descriptors;
215
- bool isEnd ;
220
+ bool IsEnd ;
216
221
};
217
222
218
223
using FallibleMemory64Iterator = llvm::fallible_iterator<Memory64Iterator>;
0 commit comments