diff options
| author | 2016-08-24 11:23:13 -0700 | |
|---|---|---|
| committer | 2016-08-24 11:23:13 -0700 | |
| commit | e71ecb2c4df15f727f51a0e1b65459f071853e35 (patch) | |
| tree | 0b87e8d0c0e2fe4dcd1d186fe1546b3b4489b002 /tools/aapt2/StringPool.cpp | |
| parent | 5d4732555dd0f1611de037dee59e0006da23be46 (diff) | |
| parent | 29835cc56eb26089cd8d2c21c7507c9d0588ceb0 (diff) | |
Merge remote-tracking branch 'goog/stage-aosp-master' into HEAD
Change-Id: I1c7301e4e6d7e5fed1fd57d2fb9cb65baf819de0
Diffstat (limited to 'tools/aapt2/StringPool.cpp')
| -rw-r--r-- | tools/aapt2/StringPool.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/tools/aapt2/StringPool.cpp b/tools/aapt2/StringPool.cpp index c19aa98a70ac..aadb00b6be2a 100644 --- a/tools/aapt2/StringPool.cpp +++ b/tools/aapt2/StringPool.cpp @@ -14,10 +14,10 @@ * limitations under the License. */ -#include "BigBuffer.h" -#include "StringPiece.h" #include "StringPool.h" -#include "Util.h" +#include "util/BigBuffer.h" +#include "util/StringPiece.h" +#include "util/Util.h" #include <algorithm> #include <androidfw/ResourceTypes.h> @@ -219,7 +219,7 @@ void StringPool::prune() { auto indexIter = std::begin(mIndexedStrings); while (indexIter != iterEnd) { if (indexIter->second->ref <= 0) { - mIndexedStrings.erase(indexIter++); + indexIter = mIndexedStrings.erase(indexIter); } else { ++indexIter; } @@ -241,6 +241,12 @@ void StringPool::prune() { // a deleted string from the StyleEntry. mStrings.erase(endIter2, std::end(mStrings)); mStyles.erase(endIter3, std::end(mStyles)); + + // Reassign the indices. + const size_t len = mStrings.size(); + for (size_t index = 0; index < len; index++) { + mStrings[index]->index = index; + } } void StringPool::sort(const std::function<bool(const Entry&, const Entry&)>& cmp) { @@ -336,7 +342,14 @@ bool StringPool::flatten(BigBuffer* out, const StringPool& pool, bool utf8) { // Encode the actual UTF16 string length. data = encodeLength(data, entry->value.size()); - strncpy16(data, entry->value.data(), entry->value.size()); + const size_t byteLength = entry->value.size() * sizeof(char16_t); + + // NOTE: For some reason, strncpy16(data, entry->value.data(), entry->value.size()) + // truncates the string. + memcpy(data, entry->value.data(), byteLength); + + // The null-terminating character is already here due to the block of data being set + // to 0s on allocation. } } |