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

Side by Side Diff: courgette/disassembler.cc

Issue 1792603006: Revert of [Courgette] Clean up Disassembler; fix ELF Memory leaks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « courgette/disassembler.h ('k') | courgette/disassembler_elf_32.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
9 namespace courgette { 7 namespace courgette {
10 8
11 Disassembler::Disassembler(const void* start, size_t length) 9 Disassembler::Disassembler(const void* start, size_t length)
12 : failure_reason_("uninitialized") { 10 : failure_reason_("uninitialized") {
13 start_ = reinterpret_cast<const uint8_t*>(start); 11 start_ = reinterpret_cast<const uint8_t*>(start);
14 length_ = length; 12 length_ = length;
15 end_ = start_ + length_; 13 end_ = start_ + length_;
16 }; 14 };
17 15
18 Disassembler::~Disassembler() {}; 16 Disassembler::~Disassembler() {};
19 17
20 const uint8_t* Disassembler::FileOffsetToPointer(FileOffset file_offset) const { 18 const uint8_t* Disassembler::OffsetToPointer(size_t offset) const {
21 CHECK_LE(file_offset, static_cast<FileOffset>(end_ - start_)); 19 assert(start_ + offset <= end_);
22 return start_ + file_offset; 20 return start_ + 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);
31 } 21 }
32 22
33 bool Disassembler::Good() { 23 bool Disassembler::Good() {
34 failure_reason_ = nullptr; 24 failure_reason_ = NULL;
35 return true; 25 return true;
36 } 26 }
37 27
38 bool Disassembler::Bad(const char* reason) { 28 bool Disassembler::Bad(const char* reason) {
39 failure_reason_ = reason; 29 failure_reason_ = reason;
40 return false; 30 return false;
41 } 31 }
42 32
43 void Disassembler::ReduceLength(size_t reduced_length) { 33 void Disassembler::ReduceLength(size_t reduced_length) {
44 CHECK_LE(reduced_length, length_); 34 CHECK_LE(reduced_length, length_);
45 length_ = reduced_length; 35 length_ = reduced_length;
46 end_ = start_ + length_; 36 end_ = start_ + length_;
47 } 37 }
48 38
49 } // namespace courgette 39 } // namespace courgette
OLDNEW
« no previous file with comments | « courgette/disassembler.h ('k') | courgette/disassembler_elf_32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698