OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #include "minidump/minidump_string_writer_test_util.h" |
| 16 |
| 17 #include "gtest/gtest.h" |
| 18 #include "minidump/minidump_extensions.h" |
| 19 |
| 20 namespace crashpad { |
| 21 namespace test { |
| 22 |
| 23 std::string MinidumpUTF8StringAtRVA(const StringFileWriter& file_writer, |
| 24 RVA rva) { |
| 25 const std::string& contents = file_writer.string(); |
| 26 if (rva == 0) { |
| 27 return std::string(); |
| 28 } |
| 29 |
| 30 if (rva + sizeof(MinidumpUTF8String) > contents.size()) { |
| 31 ADD_FAILURE() |
| 32 << "rva " << rva << " too large for contents " << contents.size(); |
| 33 return std::string(); |
| 34 } |
| 35 |
| 36 const MinidumpUTF8String* minidump_string = |
| 37 reinterpret_cast<const MinidumpUTF8String*>(&contents[rva]); |
| 38 |
| 39 // Verify that the file has enough data for the string’s stated length plus |
| 40 // its required NUL terminator. |
| 41 if (rva + sizeof(MinidumpUTF8String) + minidump_string->Length + 1 > |
| 42 contents.size()) { |
| 43 ADD_FAILURE() |
| 44 << "rva " << rva << ", length " << minidump_string->Length |
| 45 << " too large for contents " << contents.size(); |
| 46 return std::string(); |
| 47 } |
| 48 |
| 49 std::string minidump_string_data( |
| 50 reinterpret_cast<const char*>(&minidump_string->Buffer[0]), |
| 51 minidump_string->Length); |
| 52 return minidump_string_data; |
| 53 } |
| 54 |
| 55 } // namespace test |
| 56 } // namespace crashpad |
OLD | NEW |