Merge "Add explicit Result::ok() checks where needed"
This commit is contained in:
@@ -71,7 +71,7 @@ Result<ResourceId> WARN_UNUSED ParseResReference(const AssetManager2& am, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// next, try to parse as a package:type/name string
|
// next, try to parse as a package:type/name string
|
||||||
if (auto resid = am.GetResourceId(res, "", fallback_package)) {
|
if (auto resid = am.GetResourceId(res, "", fallback_package); resid.ok()) {
|
||||||
return *resid;
|
return *resid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ void PrintValue(AssetManager2* const am, const AssetManager2::SelectedValue& val
|
|||||||
case Res_value::TYPE_STRING: {
|
case Res_value::TYPE_STRING: {
|
||||||
const ResStringPool* pool = am->GetStringPoolForCookie(value.cookie);
|
const ResStringPool* pool = am->GetStringPoolForCookie(value.cookie);
|
||||||
out->append("\"");
|
out->append("\"");
|
||||||
if (auto str = pool->string8ObjectAt(value.data)) {
|
if (auto str = pool->string8ObjectAt(value.data); str.ok()) {
|
||||||
out->append(*str);
|
out->append(*str);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ Result<std::string> XmlParser::Node::GetAttributeStringValue(const std::string&
|
|||||||
|
|
||||||
switch ((*value).dataType) {
|
switch ((*value).dataType) {
|
||||||
case Res_value::TYPE_STRING: {
|
case Res_value::TYPE_STRING: {
|
||||||
if (auto str = parser_.getStrings().string8ObjectAt((*value).data)) {
|
if (auto str = parser_.getStrings().string8ObjectAt((*value).data); str.ok()) {
|
||||||
return std::string(str->string());
|
return std::string(str->string());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -670,7 +670,7 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntryInternal(
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto entry_flags = type_spec->GetFlagsForEntryIndex(entry_idx);
|
auto entry_flags = type_spec->GetFlagsForEntryIndex(entry_idx);
|
||||||
if (UNLIKELY(!entry_flags)) {
|
if (UNLIKELY(!entry_flags.has_value())) {
|
||||||
return base::unexpected(entry_flags.error());
|
return base::unexpected(entry_flags.error());
|
||||||
}
|
}
|
||||||
type_flags |= entry_flags.value();
|
type_flags |= entry_flags.value();
|
||||||
|
|||||||
@@ -897,12 +897,12 @@ base::expected<StringPiece, NullOrIOError> ResStringPool::string8At(size_t idx)
|
|||||||
// Decode the UTF-16 length. This is not used if we're not
|
// Decode the UTF-16 length. This is not used if we're not
|
||||||
// converting to UTF-16 from UTF-8.
|
// converting to UTF-16 from UTF-8.
|
||||||
const base::expected<size_t, IOError> u16len = decodeLength(&str);
|
const base::expected<size_t, IOError> u16len = decodeLength(&str);
|
||||||
if (UNLIKELY(!u16len)) {
|
if (UNLIKELY(!u16len.has_value())) {
|
||||||
return base::unexpected(u16len.error());
|
return base::unexpected(u16len.error());
|
||||||
}
|
}
|
||||||
|
|
||||||
const base::expected<size_t, IOError> u8len = decodeLength(&str);
|
const base::expected<size_t, IOError> u8len = decodeLength(&str);
|
||||||
if (UNLIKELY(!u8len)) {
|
if (UNLIKELY(!u8len.has_value())) {
|
||||||
return base::unexpected(u8len.error());
|
return base::unexpected(u8len.error());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ base::expected<AssetManager2::ResourceName, NullOrIOError> ToResourceName(
|
|||||||
.package_len = package_name.size(),
|
.package_len = package_name.size(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (base::expected<StringPiece, NullOrIOError> type_str = type_string_ref.string8()) {
|
if (base::expected<StringPiece, NullOrIOError> type_str = type_string_ref.string8();
|
||||||
|
type_str.ok()) {
|
||||||
name.type = type_str->data();
|
name.type = type_str->data();
|
||||||
name.type_len = type_str->size();
|
name.type_len = type_str->size();
|
||||||
} else if (UNLIKELY(IsIOError(type_str))) {
|
} else if (UNLIKELY(IsIOError(type_str))) {
|
||||||
@@ -64,7 +65,8 @@ base::expected<AssetManager2::ResourceName, NullOrIOError> ToResourceName(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (name.type == nullptr) {
|
if (name.type == nullptr) {
|
||||||
if (base::expected<StringPiece16, NullOrIOError> type16_str = type_string_ref.string16()) {
|
if (base::expected<StringPiece16, NullOrIOError> type16_str = type_string_ref.string16();
|
||||||
|
type16_str.ok()) {
|
||||||
name.type16 = type16_str->data();
|
name.type16 = type16_str->data();
|
||||||
name.type_len = type16_str->size();
|
name.type_len = type16_str->size();
|
||||||
} else if (!type16_str.has_value()) {
|
} else if (!type16_str.has_value()) {
|
||||||
@@ -72,7 +74,8 @@ base::expected<AssetManager2::ResourceName, NullOrIOError> ToResourceName(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base::expected<StringPiece, NullOrIOError> entry_str = entry_string_ref.string8()) {
|
if (base::expected<StringPiece, NullOrIOError> entry_str = entry_string_ref.string8();
|
||||||
|
entry_str.ok()) {
|
||||||
name.entry = entry_str->data();
|
name.entry = entry_str->data();
|
||||||
name.entry_len = entry_str->size();
|
name.entry_len = entry_str->size();
|
||||||
} else if (UNLIKELY(IsIOError(entry_str))) {
|
} else if (UNLIKELY(IsIOError(entry_str))) {
|
||||||
@@ -80,7 +83,8 @@ base::expected<AssetManager2::ResourceName, NullOrIOError> ToResourceName(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (name.entry == nullptr) {
|
if (name.entry == nullptr) {
|
||||||
if (base::expected<StringPiece16, NullOrIOError> entry16_str = entry_string_ref.string16()) {
|
if (base::expected<StringPiece16, NullOrIOError> entry16_str = entry_string_ref.string16();
|
||||||
|
entry16_str.ok()) {
|
||||||
name.entry16 = entry16_str->data();
|
name.entry16 = entry16_str->data();
|
||||||
name.entry_len = entry16_str->size();
|
name.entry_len = entry16_str->size();
|
||||||
} else if (!entry16_str.has_value()) {
|
} else if (!entry16_str.has_value()) {
|
||||||
|
|||||||
@@ -531,14 +531,14 @@ bool ExtractResFilePathParts(const StringPiece& path, StringPiece* out_prefix,
|
|||||||
}
|
}
|
||||||
|
|
||||||
StringPiece16 GetString16(const android::ResStringPool& pool, size_t idx) {
|
StringPiece16 GetString16(const android::ResStringPool& pool, size_t idx) {
|
||||||
if (auto str = pool.stringAt(idx)) {
|
if (auto str = pool.stringAt(idx); str.ok()) {
|
||||||
return *str;
|
return *str;
|
||||||
}
|
}
|
||||||
return StringPiece16();
|
return StringPiece16();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetString(const android::ResStringPool& pool, size_t idx) {
|
std::string GetString(const android::ResStringPool& pool, size_t idx) {
|
||||||
if (auto str = pool.string8At(idx)) {
|
if (auto str = pool.string8At(idx); str.ok()) {
|
||||||
return ModifiedUtf8ToUtf8(str->to_string());
|
return ModifiedUtf8ToUtf8(str->to_string());
|
||||||
}
|
}
|
||||||
return Utf16ToUtf8(GetString16(pool, idx));
|
return Utf16ToUtf8(GetString16(pool, idx));
|
||||||
|
|||||||
Reference in New Issue
Block a user