Eliminate usage of vector<>[0] for 0-sized vectors in processor library (#84).
r=bryner
8eb9277ac0
git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@72 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
parent
c297c50f83
commit
373c49b416
1 changed files with 130 additions and 116 deletions
|
@ -643,6 +643,9 @@ const u_int8_t* MinidumpMemoryRegion::GetMemory() {
|
|||
return NULL;
|
||||
|
||||
if (!memory_) {
|
||||
if (descriptor_->memory.data_size == 0)
|
||||
return NULL;
|
||||
|
||||
if (!minidump_->SeekSet(descriptor_->memory.rva))
|
||||
return NULL;
|
||||
|
||||
|
@ -920,6 +923,7 @@ bool MinidumpThreadList::Read(u_int32_t expected_size) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (thread_count) {
|
||||
// TODO(mmentovai): verify rational size!
|
||||
scoped_ptr<MinidumpThreads> threads(
|
||||
new MinidumpThreads(thread_count, MinidumpThread(minidump_)));
|
||||
|
@ -945,6 +949,8 @@ bool MinidumpThreadList::Read(u_int32_t expected_size) {
|
|||
}
|
||||
|
||||
threads_ = threads.release();
|
||||
}
|
||||
|
||||
thread_count_ = thread_count;
|
||||
|
||||
valid_ = true;
|
||||
|
@ -1275,6 +1281,7 @@ const string* MinidumpModule::GetDebugFilename() {
|
|||
// UTF16ToUTF8 expects a vector<u_int16_t>, so create a temporary one and
|
||||
// copy the UTF-16 data into it.
|
||||
vector<u_int16_t> string_utf16(utf16_words);
|
||||
if (utf16_words)
|
||||
memcpy(&string_utf16[0], &misc_record->data, bytes);
|
||||
|
||||
// GetMiscRecord already byte-swapped the data[] field if it contains
|
||||
|
@ -1451,6 +1458,7 @@ bool MinidumpModuleList::Read(u_int32_t expected_size) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (module_count) {
|
||||
// TODO(mmentovai): verify rational size!
|
||||
scoped_ptr<MinidumpModules> modules(
|
||||
new MinidumpModules(module_count, MinidumpModule(minidump_)));
|
||||
|
@ -1466,7 +1474,7 @@ bool MinidumpModuleList::Read(u_int32_t expected_size) {
|
|||
|
||||
u_int64_t base_address = module->base_address();
|
||||
u_int64_t module_size = module->size();
|
||||
if (base_address == (u_int64_t)-1)
|
||||
if (base_address == static_cast<u_int64_t>(-1))
|
||||
return false;
|
||||
|
||||
if (!range_map_->StoreRange(base_address, module_size, module_index))
|
||||
|
@ -1474,6 +1482,8 @@ bool MinidumpModuleList::Read(u_int32_t expected_size) {
|
|||
}
|
||||
|
||||
modules_ = modules.release();
|
||||
}
|
||||
|
||||
module_count_ = module_count;
|
||||
|
||||
valid_ = true;
|
||||
|
@ -1566,6 +1576,7 @@ bool MinidumpMemoryList::Read(u_int32_t expected_size) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (region_count) {
|
||||
// TODO(mmentovai): verify rational size!
|
||||
scoped_ptr<MemoryDescriptors> descriptors(
|
||||
new MemoryDescriptors(region_count));
|
||||
|
@ -1586,7 +1597,7 @@ bool MinidumpMemoryList::Read(u_int32_t expected_size) {
|
|||
MDMemoryDescriptor* descriptor = &(*descriptors)[region_index];
|
||||
|
||||
if (minidump_->swap())
|
||||
Swap(&*descriptor);
|
||||
Swap(descriptor);
|
||||
|
||||
u_int64_t base_address = descriptor->start_of_memory_range;
|
||||
u_int32_t region_size = descriptor->memory.data_size;
|
||||
|
@ -1603,9 +1614,11 @@ bool MinidumpMemoryList::Read(u_int32_t expected_size) {
|
|||
(*regions)[region_index].SetDescriptor(descriptor);
|
||||
}
|
||||
|
||||
region_count_ = region_count;
|
||||
descriptors_ = descriptors.release();
|
||||
regions_ = regions.release();
|
||||
}
|
||||
|
||||
region_count_ = region_count;
|
||||
|
||||
valid_ = true;
|
||||
return true;
|
||||
|
@ -2110,7 +2123,7 @@ void MinidumpAirbagInfo::Print() {
|
|||
Minidump::Minidump(const string& path)
|
||||
: header_(),
|
||||
directory_(NULL),
|
||||
stream_map_(NULL),
|
||||
stream_map_(new MinidumpStreamMap()),
|
||||
path_(path),
|
||||
fd_(-1),
|
||||
swap_(false),
|
||||
|
@ -2147,8 +2160,7 @@ bool Minidump::Read() {
|
|||
// Invalidate cached data.
|
||||
delete directory_;
|
||||
directory_ = NULL;
|
||||
delete stream_map_;
|
||||
stream_map_ = NULL;
|
||||
stream_map_->clear();
|
||||
|
||||
valid_ = false;
|
||||
|
||||
|
@ -2195,6 +2207,7 @@ bool Minidump::Read() {
|
|||
if (!SeekSet(header_.stream_directory_rva))
|
||||
return false;
|
||||
|
||||
if (header_.stream_count) {
|
||||
// TODO(mmentovai): verify rational size!
|
||||
scoped_ptr<MinidumpDirectoryEntries> directory(
|
||||
new MinidumpDirectoryEntries(header_.stream_count));
|
||||
|
@ -2205,8 +2218,6 @@ bool Minidump::Read() {
|
|||
sizeof(MDRawDirectory) * header_.stream_count))
|
||||
return false;
|
||||
|
||||
scoped_ptr<MinidumpStreamMap> stream_map(new MinidumpStreamMap());
|
||||
|
||||
for (unsigned int stream_index = 0;
|
||||
stream_index < header_.stream_count;
|
||||
++stream_index) {
|
||||
|
@ -2217,7 +2228,7 @@ bool Minidump::Read() {
|
|||
Swap(&directory_entry->location);
|
||||
}
|
||||
|
||||
// Initialize the stream_map map, which speeds locating a stream by
|
||||
// Initialize the stream_map_ map, which speeds locating a stream by
|
||||
// type.
|
||||
unsigned int stream_type = directory_entry->stream_type;
|
||||
switch (stream_type) {
|
||||
|
@ -2228,7 +2239,7 @@ bool Minidump::Read() {
|
|||
case MD_SYSTEM_INFO_STREAM:
|
||||
case MD_MISC_INFO_STREAM:
|
||||
case MD_AIRBAG_INFO_STREAM: {
|
||||
if (stream_map->find(stream_type) != stream_map->end()) {
|
||||
if (stream_map_->find(stream_type) != stream_map_->end()) {
|
||||
// Another stream with this type was already found. A minidump
|
||||
// file should contain at most one of each of these stream types.
|
||||
return false;
|
||||
|
@ -2239,13 +2250,13 @@ bool Minidump::Read() {
|
|||
default: {
|
||||
// Overwrites for stream types other than those above, but it's
|
||||
// expected to be the user's burden in that case.
|
||||
(*stream_map)[stream_type].stream_index = stream_index;
|
||||
(*stream_map_)[stream_type].stream_index = stream_index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
directory_ = directory.release();
|
||||
stream_map_ = stream_map.release();
|
||||
}
|
||||
|
||||
valid_ = true;
|
||||
return true;
|
||||
|
@ -2391,8 +2402,11 @@ string* Minidump::ReadString(off_t offset) {
|
|||
// TODO(mmentovai): verify rational size!
|
||||
vector<u_int16_t> string_utf16(utf16_words);
|
||||
|
||||
if (!ReadBytes(&string_utf16[0], bytes))
|
||||
if (utf16_words) {
|
||||
if (!ReadBytes(&string_utf16[0], bytes)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return UTF16ToUTF8(string_utf16, swap_);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue