OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ppapi/proxy/pdf_resource.h" | 5 #include "ppapi/proxy/pdf_resource.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 while (match_start != USEARCH_DONE) { | 91 while (match_start != USEARCH_DONE) { |
92 int32_t matched_length = usearch_getMatchedLength(searcher); | 92 int32_t matched_length = usearch_getMatchedLength(searcher); |
93 PP_PrivateFindResult result; | 93 PP_PrivateFindResult result; |
94 result.start_index = match_start; | 94 result.start_index = match_start; |
95 result.length = matched_length; | 95 result.length = matched_length; |
96 pp_results.push_back(result); | 96 pp_results.push_back(result); |
97 match_start = usearch_next(searcher, &status); | 97 match_start = usearch_next(searcher, &status); |
98 DCHECK(status == U_ZERO_ERROR); | 98 DCHECK(status == U_ZERO_ERROR); |
99 } | 99 } |
100 | 100 |
101 *count = static_cast<uint32_t>(pp_results.size()); | 101 if (pp_results.empty() || |
102 if (*count) { | 102 pp_results.size() > std::numeric_limits<uint32_t>::max() || |
103 *results = reinterpret_cast<PP_PrivateFindResult*>(malloc( | 103 pp_results.size() > SIZE_MAX / sizeof(PP_PrivateFindResult)) { |
104 *count * sizeof(PP_PrivateFindResult))); | 104 *count = 0; |
105 memcpy(*results, &pp_results[0], *count * sizeof(PP_PrivateFindResult)); | 105 *results = nullptr; |
106 } else { | 106 } else { |
107 *results = NULL; | 107 *count = static_cast<uint32_t>(pp_results.size()); |
| 108 const size_t result_size = pp_results.size() * sizeof(PP_PrivateFindResult); |
| 109 *results = reinterpret_cast<PP_PrivateFindResult*>(malloc(result_size)); |
| 110 memcpy(*results, &pp_results[0], result_size); |
108 } | 111 } |
109 | 112 |
110 usearch_close(searcher); | 113 usearch_close(searcher); |
111 } | 114 } |
112 | 115 |
113 void PDFResource::DidStartLoading() { | 116 void PDFResource::DidStartLoading() { |
114 Post(RENDERER, PpapiHostMsg_PDF_DidStartLoading()); | 117 Post(RENDERER, PpapiHostMsg_PDF_DidStartLoading()); |
115 } | 118 } |
116 | 119 |
117 void PDFResource::DidStopLoading() { | 120 void PDFResource::DidStopLoading() { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 void PDFResource::GetV8ExternalSnapshotData(const char** natives_data_out, | 212 void PDFResource::GetV8ExternalSnapshotData(const char** natives_data_out, |
210 int* natives_size_out, | 213 int* natives_size_out, |
211 const char** snapshot_data_out, | 214 const char** snapshot_data_out, |
212 int* snapshot_size_out) { | 215 int* snapshot_size_out) { |
213 gin::V8Initializer::GetV8ExternalSnapshotData( | 216 gin::V8Initializer::GetV8ExternalSnapshotData( |
214 natives_data_out, natives_size_out, snapshot_data_out, snapshot_size_out); | 217 natives_data_out, natives_size_out, snapshot_data_out, snapshot_size_out); |
215 } | 218 } |
216 | 219 |
217 } // namespace proxy | 220 } // namespace proxy |
218 } // namespace ppapi | 221 } // namespace ppapi |
OLD | NEW |