Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: courgette/disassembler.cc

Issue 1676683002: [Courgette] Clean up Disassembler; fix ELF Memory leaks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "courgette/disassembler.h" 5 #include "courgette/disassembler.h"
6 6
7 #include "base/logging.h"
8
7 namespace courgette { 9 namespace courgette {
8 10
9 Disassembler::Disassembler(const void* start, size_t length) 11 Disassembler::Disassembler(const void* start, size_t length)
10 : failure_reason_("uninitialized") { 12 : failure_reason_("uninitialized") {
11 start_ = reinterpret_cast<const uint8_t*>(start); 13 start_ = reinterpret_cast<const uint8_t*>(start);
12 length_ = length; 14 length_ = length;
13 end_ = start_ + length_; 15 end_ = start_ + length_;
14 }; 16 };
15 17
16 Disassembler::~Disassembler() {}; 18 Disassembler::~Disassembler() {};
17 19
18 const uint8_t* Disassembler::OffsetToPointer(size_t offset) const { 20 const uint8_t* Disassembler::FileOffsetToPointer(FileOffset file_offset) const {
19 assert(start_ + offset <= end_); 21 CHECK_LE(file_offset, static_cast<FileOffset>(end_ - start_));
20 return start_ + offset; 22 return start_ + file_offset;
23 }
24
25 const uint8_t* Disassembler::RVAToPointer(RVA rva) const {
26 FileOffset file_offset = RVAToFileOffset(rva);
27 if (file_offset == kNoFileOffset)
28 return nullptr;
29
30 return FileOffsetToPointer(file_offset);
21 } 31 }
22 32
23 bool Disassembler::Good() { 33 bool Disassembler::Good() {
24 failure_reason_ = NULL; 34 failure_reason_ = nullptr;
25 return true; 35 return true;
26 } 36 }
27 37
28 bool Disassembler::Bad(const char* reason) { 38 bool Disassembler::Bad(const char* reason) {
29 failure_reason_ = reason; 39 failure_reason_ = reason;
30 return false; 40 return false;
31 } 41 }
32 42
33 void Disassembler::ReduceLength(size_t reduced_length) { 43 void Disassembler::ReduceLength(size_t reduced_length) {
34 CHECK_LE(reduced_length, length_); 44 CHECK_LE(reduced_length, length_);
35 length_ = reduced_length; 45 length_ = reduced_length;
36 end_ = start_ + length_; 46 end_ = start_ + length_;
37 } 47 }
38 48
39 } // namespace courgette 49 } // namespace courgette
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698