| 971 | } |
| 972 | |
| 973 | void BinaryAnnotator::BuildString(const uint64_t string_offset, |
| 974 | const reflection::Object *const table, |
| 975 | const reflection::Field *const field) { |
| 976 | // Check if we have already generated this string section, and this is a |
| 977 | // shared string instance. |
| 978 | if (ContainsSection(string_offset)) { return; } |
| 979 | |
| 980 | std::vector<BinaryRegion> regions; |
| 981 | const auto string_length = ReadScalar<uint32_t>(string_offset); |
| 982 | |
| 983 | BinaryRegionComment string_length_comment; |
| 984 | string_length_comment.type = BinaryRegionCommentType::StringLength; |
| 985 | |
| 986 | if (!string_length.has_value()) { |
| 987 | const uint64_t remaining = RemainingBytes(string_offset); |
| 988 | |
| 989 | SetError(string_length_comment, BinaryRegionStatus::ERROR_INCOMPLETE_BINARY, |
| 990 | "4"); |
| 991 | |
| 992 | regions.push_back(MakeBinaryRegion(string_offset, remaining, |
| 993 | BinaryRegionType::Unknown, remaining, 0, |
| 994 | string_length_comment)); |
| 995 | |
| 996 | } else { |
| 997 | const uint32_t string_size = string_length.value(); |
| 998 | const uint64_t string_end = |
| 999 | string_offset + sizeof(uint32_t) + string_size + sizeof(char); |
| 1000 | |
| 1001 | if (!IsValidOffset(string_end - 1)) { |
| 1002 | SetError(string_length_comment, |
| 1003 | BinaryRegionStatus::ERROR_LENGTH_TOO_LONG); |
| 1004 | |
| 1005 | regions.push_back(MakeBinaryRegion(string_offset, sizeof(uint32_t), |
| 1006 | BinaryRegionType::Uint32, 0, 0, |
| 1007 | string_length_comment)); |
| 1008 | } else { |
| 1009 | regions.push_back(MakeBinaryRegion(string_offset, sizeof(uint32_t), |
| 1010 | BinaryRegionType::Uint32, 0, 0, |
| 1011 | string_length_comment)); |
| 1012 | |
| 1013 | BinaryRegionComment string_comment; |
| 1014 | string_comment.type = BinaryRegionCommentType::StringValue; |
| 1015 | |
| 1016 | regions.push_back(MakeBinaryRegion(string_offset + sizeof(uint32_t), |
| 1017 | string_size, BinaryRegionType::Char, |
| 1018 | string_size, 0, string_comment)); |
| 1019 | |
| 1020 | BinaryRegionComment string_terminator_comment; |
| 1021 | string_terminator_comment.type = |
| 1022 | BinaryRegionCommentType::StringTerminator; |
| 1023 | |
| 1024 | regions.push_back(MakeBinaryRegion( |
| 1025 | string_offset + sizeof(uint32_t) + string_size, sizeof(char), |
| 1026 | BinaryRegionType::Char, 0, 0, string_terminator_comment)); |
| 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | AddSection(string_offset, |
nothing calls this directly
no test coverage detected