The following issues were found
src/mongo/platform/endian_test.cpp
1 issues
Line: 42
const bool kNativeLittle = (endian::Order::kNative == endian::Order::kLittle);
TEST(EndianTest, NativeToBig_uint16_t) {
uint8_t le_buf[] = {0x01, 0x02};
uint8_t be_buf[] = {0x02, 0x01};
uint16_t le;
uint16_t be;
std::memcpy(&le, le_buf, sizeof(le));
Reported by Cppcheck.
src/mongo/platform/mutex_test.cpp
1 issues
Line: 51
auto gMutex = MONGO_MAKE_LATCH();
} // anonymous namespace
TEST(MutexTest, Macros) {
// Verify a pure inline latch
auto constexpr kLatchName = "inlineLatchForTest";
auto m1 = MONGO_MAKE_LATCH(kLatchName);
static_assert(std::is_same_v<decltype(m1), Mutex>);
ASSERT_EQ(m1.getName(), kLatchName);
Reported by Cppcheck.
src/mongo/platform/overflow_arithmetic_test.cpp
1 issues
Line: 74
constexpr auto polyAdd = [](auto&&... a) { return overflow::add(a...); };
constexpr auto polySub = [](auto&&... a) { return overflow::sub(a...); };
TEST(OverflowArithmetic, SignedMultiplicationTests) {
using T = int64_t;
static constexpr auto f = polyMul;
ASSERT(test<T>(f, 0, kMax<T>, 0));
ASSERT(test<T>(f, 0, kMin<T>, 0));
ASSERT(test<T>(f, 1, kMax<T>, kMax<T>));
Reported by Cppcheck.
src/mongo/platform/process_id_test.cpp
1 issues
Line: 65
ASSERT_FALSE(p1 >= p2);
}
TEST(ProcessId, GetCurrentEqualsSelf) {
ASSERT_EQUALS(ProcessId::getCurrent(), ProcessId::getCurrent());
}
} // namespace
} // namespace mongo
Reported by Cppcheck.
src/mongo/platform/random.h
1 issues
Line: 141
Column: 18
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
while (written < n) {
uint64_t t = nextInt64();
size_t w = std::min(n - written, sizeof(t));
std::memcpy(p + written, &t, w);
written += w;
}
}
private:
Reported by FlawFinder.
src/mongo/platform/random_test.cpp
1 issues
Line: 51
}
}
TEST(RandomTest, Seed2) {
PseudoRandom a(12);
PseudoRandom b(12);
for (int i = 0; i < 100; i++) {
ASSERT_EQUALS(a.nextInt64(), b.nextInt64());
Reported by Cppcheck.
src/mongo/platform/source_location_test.cpp
1 issues
Line: 52
#define CALL_MONGO_SOURCE_LOCATION() MONGO_SOURCE_LOCATION()
TEST(SourceLocation, CorrectLineNumber) {
using LineT = std::invoke_result_t<decltype(&SourceLocation::line), SourceLocation>;
ASSERT_EQ(MONGO_SOURCE_LOCATION().line(), static_cast<LineT>(__LINE__));
}
TEST(SourceLocation, InlineVariable) {
Reported by Cppcheck.
src/mongo/platform/stack_locator_test.cpp
1 issues
Line: 60
ASSERT_TRUE(size.get() > available.get());
}
TEST(StackLocator, StacksGrowsDown) {
// The current implementation assumes a downward growing stack. Write a test
// that confirms that the current platform is downward growing, so that if the
// system is ever ported to an upward growing stack, we get a test failure.
const StackLocator locator;
Reported by Cppcheck.
src/mongo/rpc/get_status_from_command_result_test.cpp
1 issues
Line: 46
}
} // namespace
TEST(GetStatusFromCommandResult, Ok) {
ASSERT_OK(statusFor("{ok: 1.0}"));
}
TEST(GetStatusFromCommandResult, OkIgnoresCode) {
ASSERT_OK(statusFor("{ok: 1.0, code: 12345, errmsg: 'oh no!'}"));
Reported by Cppcheck.
src/mongo/rpc/metadata/client_metadata_test.cpp
1 issues
Line: 83
} while (0)
TEST(ClientMetadataTest, TestLoopbackTest) {
// serializePrivate with appName
{
BSONObjBuilder builder;
ASSERT_OK(ClientMetadata::serializePrivate("a", "b", "c", "d", "e", "f", "g", &builder));
Reported by Cppcheck.