Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0315c849 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Don't dereference a null pointer"

parents 7264b348 949b6253
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -32,6 +32,14 @@ namespace android {
// WARNING: When creating from std::basic_string<>, moving the original
// std::basic_string<> will invalidate the data held in a BasicStringPiece<>.
// BasicStringPiece<> should only be used transitively.
//
// NOTE: When creating an std::pair<StringPiece, T> using std::make_pair(),
// passing an std::string will first copy the string, then create a StringPiece
// on the copy, which is then immediately destroyed.
// Instead, create a StringPiece explicitly:
//
// std::string my_string = "foo";
// std::make_pair<StringPiece, T>(StringPiece(my_string), ...);
template <typename TChar>
class BasicStringPiece {
 public:
+3 −2
Original line number Diff line number Diff line
@@ -347,7 +347,9 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res
  }

  // Add the Styleable array to the Styleable class.
  if (out_class_def != nullptr) {
    out_class_def->AddMember(std::move(array_def));
  }

  // Now we emit the indices into the array.
  for (size_t i = 0; i < attr_count; i++) {
@@ -578,7 +580,6 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate,
  if (out_r_txt != nullptr) {
    r_txt_printer = util::make_unique<Printer>(out_r_txt);
  }

  // Generate an onResourcesLoaded() callback if requested.
  if (out != nullptr && options_.rewrite_callback_options) {
    rewrite_method =
+18 −0
Original line number Diff line number Diff line
@@ -438,4 +438,22 @@ TEST(JavaClassGeneratorTest, GenerateOnResourcesLoadedCallbackForSharedLibrary)
  EXPECT_THAT(output, HasSubstr("com.boo.R.onResourcesLoaded"));
}

TEST(JavaClassGeneratorTest, OnlyGenerateRText) {
  std::unique_ptr<ResourceTable> table =
      test::ResourceTableBuilder()
          .SetPackageId("android", 0x01)
          .AddValue("android:attr/foo", ResourceId(0x01010000), util::make_unique<Attribute>())
          .AddValue("android:styleable/hey.dude", ResourceId(0x01020000),
                    test::StyleableBuilder()
                        .AddItem("android:attr/foo", ResourceId(0x01010000))
                        .Build())
          .Build();

  std::unique_ptr<IAaptContext> context =
      test::ContextBuilder().SetPackageId(0x01).SetCompilationPackage("android").Build();
  JavaClassGenerator generator(context.get(), table.get(), {});

  ASSERT_TRUE(generator.Generate("android", nullptr));
}

}  // namespace aapt