The following issues were found

java/core/src/main/java/com/google/protobuf/Android.java
1 issues
A catch statement should never catch throwable since it includes errors.
Error

Line: 60

                private static <T> Class<T> getClassForName(String name) {
    try {
      return (Class<T>) Class.forName(name);
    } catch (Throwable e) {
      return null;
    }
  }
}

            

Reported by PMD.

src/google/protobuf/compiler/python/python_plugin_unittest.cc
1 issues
syntax error
Error

Line: 83

              // This test verifies that all the expected insertion points exist.  It does
// not verify that they are correctly-placed; that would require actually
// compiling the output which is a bit more than I care to do for this test.
TEST(PythonPluginTest, PluginTest) {
  GOOGLE_CHECK_OK(File::SetContents(TestTempDir() + "/test.proto",
                             "syntax = \"proto2\";\n"
                             "package foo;\n"
                             "message Bar {\n"
                             "  message Baz {}\n"

            

Reported by Cppcheck.

src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc
1 issues
StrCat - Does not check for buffer overflows when concatenating to destination [MS-banned]
Security

Line: 155 Column: 42 CWE codes: 120

              void PrimitiveFieldGenerator::SetExtraRuntimeHasBitsBase(int has_base) {
  if (GetObjectiveCType(descriptor_) == OBJECTIVECTYPE_BOOLEAN) {
    // Set into the offset the has bit to use for the actual value.
    variables_["storage_offset_value"] = StrCat(has_base);
    variables_["storage_offset_comment"] =
        "  // Stored in _has_storage_ to save space.";
  }
}


            

Reported by FlawFinder.

src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc
1 issues
syntax error
Error

Line: 78

                EXPECT_EQ(expected, result);
}

TEST(ObjCHelper, TextFormatDecodeData_DecodeDataForString_ByteCodes) {
  std::string input_for_decode("abcdefghIJ");
  std::string desired_output_for_decode;
  std::string expected;
  std::string result;


            

Reported by Cppcheck.

src/google/protobuf/compiler/objectivec/objectivec_file.cc
1 issues
StrCat - Does not check for buffer overflows when concatenating to destination [MS-banned]
Security

Line: 238 Column: 39 CWE codes: 120

                    "#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.\n"
      "#endif\n"
      "\n",
      "google_protobuf_objc_version", StrCat(GOOGLE_PROTOBUF_OBJC_VERSION));

  // #import any headers for "public imports" in the proto file.
  {
    ImportWriter import_writer(
        options_.generate_for_named_framework,

            

Reported by FlawFinder.

src/google/protobuf/lite_arena_unittest.cc
1 issues
syntax error
Error

Line: 54

                std::unique_ptr<Arena> arena_;
};

TEST_F(LiteArenaTest, MapNoHeapAllocation) {
  std::string data;
  data.reserve(128 * 1024);

  {
    // TODO(teboring): Enable no heap check when ArenaStringPtr is used in

            

Reported by Cppcheck.

src/google/protobuf/lite_unittest.cc
1 issues
syntax error
Error

Line: 91

                empty_message->ParseFromString(data);
}

TEST(Lite, AllLite1) {
  std::string data;

  {
    protobuf_unittest::TestAllTypesLite message, message2, message3;
    TestUtilLite::ExpectClear(message);

            

Reported by Cppcheck.

src/google/protobuf/map_field_test.cc
1 issues
syntax error
Error

Line: 151

                                       MapFieldBasePrimitiveTest,
                         testing::Values(true, false));

TEST_P(MapFieldBasePrimitiveTest, SpaceUsedExcludingSelf) {
  EXPECT_LT(0, map_field_base_->SpaceUsedExcludingSelf());
}

TEST_P(MapFieldBasePrimitiveTest, GetRepeatedField) {
  const RepeatedPtrField<Message>& repeated =

            

Reported by Cppcheck.

src/google/protobuf/message_lite.cc
1 issues
StrCat - Does not check for buffer overflows when concatenating to destination [MS-banned]
Security

Line: 69 Column: 10 CWE codes: 120

              
std::string MessageLite::DebugString() const {
  std::uintptr_t address = reinterpret_cast<std::uintptr_t>(this);
  return StrCat("MessageLite at 0x", strings::Hex(address));
}

namespace {

// When serializing, we first compute the byte size, then serialize the message.

            

Reported by FlawFinder.

src/google/protobuf/message_lite.h
1 issues
char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 160 Column: 16 CWE codes: 119 120
Suggestion: Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length

               private:
  // Prefer c++14 aligned_storage, but for compatibility this will do.
  union AlignedUnion {
    alignas(T) char space[sizeof(T)];
    int64_t align_to_int64;
    void* align_to_ptr;
  } union_;
};


            

Reported by FlawFinder.