summaryrefslogtreecommitdiff
path: root/tools/aapt2/java
diff options
context:
space:
mode:
authorPirama Arumuga Nainar <pirama@google.com>2018-09-24 15:20:15 -0700
committerPirama Arumuga Nainar <pirama@google.com>2018-09-25 13:21:35 -0700
commit9ba5cb4796a66b387af1f9350134f742f490aa7f (patch)
tree9526df3430e982770a42719f2dc6cc198353950b /tools/aapt2/java
parent4a2dd10d834529311bf0daa4d5fa7c81f903bf61 (diff)
Do not use StringPiece in ExtractJavaIdentifier
Bug: http://b/91353691 After assigning the result of TransformToFieldName to 'result', the underlying storage is destroyed after the 'if' statement of the function call. 'result' ends up with garbage if the identifier has a '-'. ManifestClassGeneratorTest.NormalizePermissionNames is broken for this reason in 32-bit Windows when using libc++ and 32-bit Linux. ASAN also reports this failure for both 32-bit and 64-bit linux. Test: Run test on the cases mentioned above and ensure all of them pass. Change-Id: I69163c423c1171b7ac7838f2abe06bdf8058df4c
Diffstat (limited to 'tools/aapt2/java')
-rw-r--r--tools/aapt2/java/ManifestClassGenerator.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/tools/aapt2/java/ManifestClassGenerator.cpp b/tools/aapt2/java/ManifestClassGenerator.cpp
index be67c9c8c03c..10e504ec0752 100644
--- a/tools/aapt2/java/ManifestClassGenerator.cpp
+++ b/tools/aapt2/java/ManifestClassGenerator.cpp
@@ -26,21 +26,20 @@
#include "util/Maybe.h"
#include "xml/XmlDom.h"
-using ::android::StringPiece;
using ::aapt::text::IsJavaIdentifier;
namespace aapt {
-static Maybe<StringPiece> ExtractJavaIdentifier(IDiagnostics* diag, const Source& source,
+static Maybe<std::string> ExtractJavaIdentifier(IDiagnostics* diag, const Source& source,
const std::string& value) {
- StringPiece result = value;
+ std::string result = value;
size_t pos = value.rfind('.');
if (pos != std::string::npos) {
result = result.substr(pos + 1);
}
// Normalize only the java identifier, leave the original value unchanged.
- if (result.contains("-")) {
+ if (result.find("-") != std::string::npos) {
result = JavaClassGenerator::TransformToFieldName(result);
}
@@ -64,7 +63,7 @@ static bool WriteSymbol(const Source& source, IDiagnostics* diag, xml::Element*
return false;
}
- Maybe<StringPiece> result =
+ Maybe<std::string> result =
ExtractJavaIdentifier(diag, source.WithLine(el->line_number), attr->value);
if (!result) {
return false;