From 5dce5e67dbdcd14882edf3f64fba671c77577ee4 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Wed, 10 Dec 2014 10:47:53 -0800 Subject: Fix issue where non-resource attributes would cause obtainStyleAttributes to fail A sentinal value of 0x00000000 was used to mark the first time an AttributeFinder was used. If the resource ID of an attribute was also 0x00000000 (which occurs with non-resource attributes, like 'style'), then it would be mistaken as the sentinel start value. Bug:18421787 Change-Id: I4be353e0f8c940cb6f262d155129f048dcc444ae --- include/androidfw/AttributeFinder.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/androidfw/AttributeFinder.h b/include/androidfw/AttributeFinder.h index a0ffeb3..acf7056 100644 --- a/include/androidfw/AttributeFinder.h +++ b/include/androidfw/AttributeFinder.h @@ -64,6 +64,7 @@ private: void jumpToClosestAttribute(uint32_t packageId); void markCurrentPackageId(uint32_t packageId); + bool mFirstTime; Iterator mBegin; Iterator mEnd; Iterator mCurrent; @@ -81,7 +82,8 @@ private: template inline BackTrackingAttributeFinder::BackTrackingAttributeFinder(const Iterator& begin, const Iterator& end) - : mBegin(begin) + : mFirstTime(true) + , mBegin(begin) , mEnd(end) , mCurrent(begin) , mLargest(begin) @@ -145,8 +147,11 @@ Iterator BackTrackingAttributeFinder::find(uint32_t attr) { return mEnd; } - if (mCurrentAttr == 0) { - // One-time initialization. + if (mFirstTime) { + // One-time initialization. We do this here instead of the constructor + // because the derived class we access in getAttribute() may not be + // fully constructed. + mFirstTime = false; mCurrentAttr = static_cast(this)->getAttribute(mBegin); mLastPackageId = getPackage(mCurrentAttr); markCurrentPackageId(mLastPackageId); -- cgit v1.1