[aapt2] Fix infinite loop in proguard::CollectLocations
std::set only works correctly when the < comparator is a strict weak
ordering, while UsageLocation::operator< was actually implementing !=.
Bug: 134190468
Change-Id: Icb9407e9c8451f9fcb4eb9b2cea310e3bcaf159e
Tested: aapt2_tests, and b/134190468#comment1
(cherry picked from commit 44fa342eb9)
This commit is contained in:
@@ -99,11 +99,13 @@ bool CollectLocations(const UsageLocation& location, const KeepSet& keep_set,
|
||||
//
|
||||
|
||||
inline bool operator==(const UsageLocation& lhs, const UsageLocation& rhs) {
|
||||
// The "source" member is ignored because we only need "name" for outputting
|
||||
// keep rules; "source" is used for comments.
|
||||
return lhs.name == rhs.name;
|
||||
}
|
||||
|
||||
inline int operator<(const UsageLocation& lhs, const UsageLocation& rhs) {
|
||||
return lhs.name.compare(rhs.name);
|
||||
inline bool operator<(const UsageLocation& lhs, const UsageLocation& rhs) {
|
||||
return lhs.name.compare(rhs.name) < 0;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@@ -364,4 +364,12 @@ TEST(ProguardRulesTest, TransitionRulesAreEmitted) {
|
||||
"-keep class com.foo.Bar { <init>(android.content.Context, android.util.AttributeSet); }"));
|
||||
}
|
||||
|
||||
TEST(ProguardRulesTest, UsageLocationComparator) {
|
||||
proguard::UsageLocation location1 = {{"pkg", ResourceType::kAttr, "x"}};
|
||||
proguard::UsageLocation location2 = {{"pkg", ResourceType::kAttr, "y"}};
|
||||
|
||||
EXPECT_EQ(location1 < location2, true);
|
||||
EXPECT_EQ(location2 < location1, false);
|
||||
}
|
||||
|
||||
} // namespace aapt
|
||||
|
||||
Reference in New Issue
Block a user