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:
mmentovai 2006-11-27 21:42:07 +00:00
parent c297c50f83
commit 373c49b416

View file

@ -643,6 +643,9 @@ const u_int8_t* MinidumpMemoryRegion::GetMemory() {
return NULL; return NULL;
if (!memory_) { if (!memory_) {
if (descriptor_->memory.data_size == 0)
return NULL;
if (!minidump_->SeekSet(descriptor_->memory.rva)) if (!minidump_->SeekSet(descriptor_->memory.rva))
return NULL; return NULL;
@ -920,6 +923,7 @@ bool MinidumpThreadList::Read(u_int32_t expected_size) {
return false; return false;
} }
if (thread_count) {
// TODO(mmentovai): verify rational size! // TODO(mmentovai): verify rational size!
scoped_ptr<MinidumpThreads> threads( scoped_ptr<MinidumpThreads> threads(
new MinidumpThreads(thread_count, MinidumpThread(minidump_))); new MinidumpThreads(thread_count, MinidumpThread(minidump_)));
@ -945,6 +949,8 @@ bool MinidumpThreadList::Read(u_int32_t expected_size) {
} }
threads_ = threads.release(); threads_ = threads.release();
}
thread_count_ = thread_count; thread_count_ = thread_count;
valid_ = true; valid_ = true;
@ -1275,6 +1281,7 @@ const string* MinidumpModule::GetDebugFilename() {
// UTF16ToUTF8 expects a vector<u_int16_t>, so create a temporary one and // UTF16ToUTF8 expects a vector<u_int16_t>, so create a temporary one and
// copy the UTF-16 data into it. // copy the UTF-16 data into it.
vector<u_int16_t> string_utf16(utf16_words); vector<u_int16_t> string_utf16(utf16_words);
if (utf16_words)
memcpy(&string_utf16[0], &misc_record->data, bytes); memcpy(&string_utf16[0], &misc_record->data, bytes);
// GetMiscRecord already byte-swapped the data[] field if it contains // GetMiscRecord already byte-swapped the data[] field if it contains
@ -1451,6 +1458,7 @@ bool MinidumpModuleList::Read(u_int32_t expected_size) {
return false; return false;
} }
if (module_count) {
// TODO(mmentovai): verify rational size! // TODO(mmentovai): verify rational size!
scoped_ptr<MinidumpModules> modules( scoped_ptr<MinidumpModules> modules(
new MinidumpModules(module_count, MinidumpModule(minidump_))); 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 base_address = module->base_address();
u_int64_t module_size = module->size(); 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; return false;
if (!range_map_->StoreRange(base_address, module_size, module_index)) 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(); modules_ = modules.release();
}
module_count_ = module_count; module_count_ = module_count;
valid_ = true; valid_ = true;
@ -1566,6 +1576,7 @@ bool MinidumpMemoryList::Read(u_int32_t expected_size) {
return false; return false;
} }
if (region_count) {
// TODO(mmentovai): verify rational size! // TODO(mmentovai): verify rational size!
scoped_ptr<MemoryDescriptors> descriptors( scoped_ptr<MemoryDescriptors> descriptors(
new MemoryDescriptors(region_count)); new MemoryDescriptors(region_count));
@ -1586,7 +1597,7 @@ bool MinidumpMemoryList::Read(u_int32_t expected_size) {
MDMemoryDescriptor* descriptor = &(*descriptors)[region_index]; MDMemoryDescriptor* descriptor = &(*descriptors)[region_index];
if (minidump_->swap()) if (minidump_->swap())
Swap(&*descriptor); Swap(descriptor);
u_int64_t base_address = descriptor->start_of_memory_range; u_int64_t base_address = descriptor->start_of_memory_range;
u_int32_t region_size = descriptor->memory.data_size; 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); (*regions)[region_index].SetDescriptor(descriptor);
} }
region_count_ = region_count;
descriptors_ = descriptors.release(); descriptors_ = descriptors.release();
regions_ = regions.release(); regions_ = regions.release();
}
region_count_ = region_count;
valid_ = true; valid_ = true;
return true; return true;
@ -2110,7 +2123,7 @@ void MinidumpAirbagInfo::Print() {
Minidump::Minidump(const string& path) Minidump::Minidump(const string& path)
: header_(), : header_(),
directory_(NULL), directory_(NULL),
stream_map_(NULL), stream_map_(new MinidumpStreamMap()),
path_(path), path_(path),
fd_(-1), fd_(-1),
swap_(false), swap_(false),
@ -2147,8 +2160,7 @@ bool Minidump::Read() {
// Invalidate cached data. // Invalidate cached data.
delete directory_; delete directory_;
directory_ = NULL; directory_ = NULL;
delete stream_map_; stream_map_->clear();
stream_map_ = NULL;
valid_ = false; valid_ = false;
@ -2195,6 +2207,7 @@ bool Minidump::Read() {
if (!SeekSet(header_.stream_directory_rva)) if (!SeekSet(header_.stream_directory_rva))
return false; return false;
if (header_.stream_count) {
// TODO(mmentovai): verify rational size! // TODO(mmentovai): verify rational size!
scoped_ptr<MinidumpDirectoryEntries> directory( scoped_ptr<MinidumpDirectoryEntries> directory(
new MinidumpDirectoryEntries(header_.stream_count)); new MinidumpDirectoryEntries(header_.stream_count));
@ -2205,8 +2218,6 @@ bool Minidump::Read() {
sizeof(MDRawDirectory) * header_.stream_count)) sizeof(MDRawDirectory) * header_.stream_count))
return false; return false;
scoped_ptr<MinidumpStreamMap> stream_map(new MinidumpStreamMap());
for (unsigned int stream_index = 0; for (unsigned int stream_index = 0;
stream_index < header_.stream_count; stream_index < header_.stream_count;
++stream_index) { ++stream_index) {
@ -2217,7 +2228,7 @@ bool Minidump::Read() {
Swap(&directory_entry->location); 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. // type.
unsigned int stream_type = directory_entry->stream_type; unsigned int stream_type = directory_entry->stream_type;
switch (stream_type) { switch (stream_type) {
@ -2228,7 +2239,7 @@ bool Minidump::Read() {
case MD_SYSTEM_INFO_STREAM: case MD_SYSTEM_INFO_STREAM:
case MD_MISC_INFO_STREAM: case MD_MISC_INFO_STREAM:
case MD_AIRBAG_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 // Another stream with this type was already found. A minidump
// file should contain at most one of each of these stream types. // file should contain at most one of each of these stream types.
return false; return false;
@ -2239,13 +2250,13 @@ bool Minidump::Read() {
default: { default: {
// Overwrites for stream types other than those above, but it's // Overwrites for stream types other than those above, but it's
// expected to be the user's burden in that case. // 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(); directory_ = directory.release();
stream_map_ = stream_map.release(); }
valid_ = true; valid_ = true;
return true; return true;
@ -2391,8 +2402,11 @@ string* Minidump::ReadString(off_t offset) {
// TODO(mmentovai): verify rational size! // TODO(mmentovai): verify rational size!
vector<u_int16_t> string_utf16(utf16_words); 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 NULL;
}
}
return UTF16ToUTF8(string_utf16, swap_); return UTF16ToUTF8(string_utf16, swap_);
} }