The following issues were found
src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc
1 issues
Line: 174
// 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(CppPluginTest, PluginTest) {
GOOGLE_CHECK_OK(File::SetContents(TestTempDir() + "/test.proto",
"syntax = \"proto2\";\n"
"package foo;\n"
"\n"
"enum Thud { VALUE = 0; }\n"
Reported by Cppcheck.
src/google/protobuf/compiler/cpp/cpp_move_unittest.cc
1 issues
Line: 65
EXPECT_NE(nested, &message1.optional_nested_message());
}
TEST(MovableMessageTest, MoveAssignmentOperator) {
protobuf_unittest::TestAllTypes message1;
TestUtil::SetAllFields(&message1);
const auto* nested = &message1.optional_nested_message();
protobuf_unittest::TestAllTypes message2;
Reported by Cppcheck.
src/google/protobuf/compiler/cpp/cpp_generator.cc
1 issues
Line: 59
Column: 10
CWE codes:
120
namespace {
std::string NumberedCcFileName(const std::string& basename, int number) {
return StrCat(basename, ".out/", number, ".cc");
}
} // namespace
bool CppGenerator::Generate(const FileDescriptor* file,
const std::string& parameter,
Reported by FlawFinder.
src/google/protobuf/stubs/substitute.cc
1 issues
Line: 119
Column: 9
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
unsigned int index = format[i+1] - '0';
assert(index < 10);
const SubstituteArg* src = args_array[index];
memcpy(target, src->data(), src->size());
target += src->size();
++i; // Skip next char.
} else if (format[i+1] == '$') {
*target++ = '$';
++i; // Skip next char.
Reported by FlawFinder.
src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc
1 issues
Line: 135
{"google/protobuf/compiler/plugin", kPluginParameter},
};
TEST(BootstrapTest, GeneratedFilesMatch) {
// We need a mapping from the actual file to virtual and actual path
// of the data to compare to.
std::map<std::string, std::string> vpath_map;
std::map<std::string, std::string> rpath_map;
rpath_map["third_party/protobuf/src/google/protobuf/test_messages_proto2"] =
Reported by Cppcheck.
src/google/protobuf/stubs/template_util.h
1 issues
Line: 62
Column: 3
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
typedef char small_;
struct big_ {
char dummy[2];
};
// Identity metafunction.
template <class T>
struct identity_ {
Reported by FlawFinder.
src/google/protobuf/stubs/template_util_unittest.cc
1 issues
Line: 54
EXPECT_GT(sizeof(GOOGLE_NAMESPACE::big_), sizeof(GOOGLE_NAMESPACE::small_));
}
TEST(TemplateUtilTest, TestIntegralConstants) {
// test the built-in types.
EXPECT_TRUE(true_type::value);
EXPECT_FALSE(false_type::value);
typedef integral_constant<int, 1> one_type;
Reported by Cppcheck.
src/google/protobuf/stubs/time_test.cc
1 issues
Line: 59
return result;
}
TEST(DateTimeTest, SimpleTime) {
DateTime time;
ASSERT_TRUE(SecondsToDateTime(1, &time));
EXPECT_EQ(1970, time.year);
EXPECT_EQ(1, time.month);
EXPECT_EQ(1, time.day);
Reported by Cppcheck.
src/google/protobuf/arenastring_unittest.cc
1 issues
Line: 72
INSTANTIATE_TEST_SUITE_P(ArenaString, SingleArena, testing::Bool());
TEST_P(SingleArena, GetSet) {
auto arena = GetArena();
ArenaStringPtr field;
field.UnsafeSetDefault(empty_default);
EXPECT_EQ("", field.Get());
field.Set(empty_default, "Test short", arena.get());
Reported by Cppcheck.
src/google/protobuf/arenastring.h
1 issues
Line: 75
Column: 34
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
// space. We don't need the string array after Init() is done.
union {
mutable InitValue init_value_;
alignas(std::string) mutable char string_buf_[sizeof(std::string)];
};
mutable std::atomic<const std::string*> inited_;
const std::string& get() const {
// This check generates less code than a call-once invocation.
Reported by FlawFinder.