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

Side by Side Diff: courgette/ensemble.cc

Issue 1629703002: [Courgette] Refactor: Manage AssemblyProgram and EncodedProgram with scoped_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix courgette_fuzzer in libfuzzer. Created 4 years, 10 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/encoded_program_unittest.cc ('k') | courgette/patch_generator_x86_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/ensemble.h" 5 #include "courgette/ensemble.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 11 #include "courgette/program_detector.h"
12 #include "courgette/region.h" 12 #include "courgette/region.h"
13 #include "courgette/simple_delta.h" 13 #include "courgette/simple_delta.h"
14 #include "courgette/streams.h" 14 #include "courgette/streams.h"
15 15
16 namespace courgette { 16 namespace courgette {
17 17
18 Element::Element(ExecutableType kind, 18 Element::Element(ExecutableType kind,
19 Ensemble* ensemble, 19 Ensemble* ensemble,
20 const Region& region) 20 const Region& region)
21 : kind_(kind), ensemble_(ensemble), region_(region) { 21 : kind_(kind), ensemble_(ensemble), region_(region) {
(...skipping 12 matching lines...) Expand all
34 // elements do not overlap. 34 // elements do not overlap.
35 Status Ensemble::FindEmbeddedElements() { 35 Status Ensemble::FindEmbeddedElements() {
36 36
37 size_t length = region_.length(); 37 size_t length = region_.length();
38 const uint8_t* start = region_.start(); 38 const uint8_t* start = region_.start();
39 39
40 size_t position = 0; 40 size_t position = 0;
41 while (position < length) { 41 while (position < length) {
42 ExecutableType type; 42 ExecutableType type;
43 size_t detected_length; 43 size_t detected_length;
44
45 Status result = DetectExecutableType(start + position, 44 Status result = DetectExecutableType(start + position,
46 length - position, 45 length - position,
47 &type, &detected_length); 46 &type, &detected_length);
48
49 if (result == C_OK) { 47 if (result == C_OK) {
50 Region region(start + position, detected_length); 48 Region region(start + position, detected_length);
51 49
52 Element* element = new Element(type, this, region); 50 Element* element = new Element(type, this, region);
53 owned_elements_.push_back(element); 51 owned_elements_.push_back(element);
54 elements_.push_back(element); 52 elements_.push_back(element);
55 position += region.length(); 53 position += region.length();
56 } else { 54 } else {
57 position++; 55 position++;
58 } 56 }
59 } 57 }
60 return C_OK; 58 return C_OK;
61 } 59 }
62 60
63 Ensemble::~Ensemble() { 61 Ensemble::~Ensemble() {
64 for (size_t i = 0; i < owned_elements_.size(); ++i) 62 for (size_t i = 0; i < owned_elements_.size(); ++i)
65 delete owned_elements_[i]; 63 delete owned_elements_[i];
66 } 64 }
67 65
68 } // namespace 66 } // namespace
OLDNEW
« no previous file with comments | « courgette/encoded_program_unittest.cc ('k') | courgette/patch_generator_x86_32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698