The following issues were found

src/mongo/db/query/query_planner_group_pushdown_test.cpp
1 issues
syntax error
Error

Line: 65

                  }
};

TEST_F(QueryPlannerGroupPushdownTest, PushdownOfASingleGroup) {
    const std::vector<BSONObj> rawPipeline = {
        fromjson("{$group: {_id: '$_id', count: {$sum: '$x'}}}"),
    };
    auto pipeline = buildTestPipeline(rawPipeline);


            

Reported by Cppcheck.

src/mongo/db/query/query_planner_hashed_index_test.cpp
1 issues
syntax error
Error

Line: 64

              //
// Range queries.
//
TEST_F(QueryPlannerHashedTest, RangeQueryWhenHashedFieldIsAPrefix) {
    addIndex(BSON("x"
                  << "hashed"
                  << "y" << 1 << "z" << -1));

    // Range query on hashed field cannot use index.

            

Reported by Cppcheck.

src/mongo/db/query/query_planner_index_test.cpp
1 issues
syntax error
Error

Line: 50

                  assertSolutionExists("{ixscan: {pattern: {x: 1}, bounds: {x: [[5,5,true,true]]}}}");
}

TEST_F(QueryPlannerTest, PlannerAddsFetchToIxscanForCountWhenFetchFilterNonempty) {
    params.options = QueryPlannerParams::IS_COUNT;
    addIndex(BSON("x" << 1));
    runQuery(BSON("y" << 3 << "x" << 5));
    ASSERT_EQUALS(getNumSolutions(), 1U);
    assertSolutionExists(

            

Reported by Cppcheck.

src/mongo/db/query/query_planner_operator_test.cpp
1 issues
syntax error
Error

Line: 54

                  assertSolutionExists("{fetch: {filter: null, node: {ixscan: {pattern: {x: 1}}}}}");
}

TEST_F(QueryPlannerTest, EqualityIndexScanWithTrailingFields) {
    addIndex(BSON("x" << 1 << "y" << 1));

    runQuery(BSON("x" << 5));

    ASSERT_EQUALS(getNumSolutions(), 2U);

            

Reported by Cppcheck.

src/mongo/db/query/query_planner_options_test.cpp
1 issues
syntax error
Error

Line: 64

              // Min/Max
//

TEST_F(QueryPlannerTest, MinValid) {
    addIndex(BSON("a" << 1));
    runQueryHintMinMax(BSONObj(), BSONObj(fromjson("{a: 1}")), fromjson("{a: 1}"), BSONObj());

    assertNumSolutions(1U);
    assertSolutionExists(

            

Reported by Cppcheck.

src/mongo/db/query/query_planner_partialidx_test.cpp
1 issues
syntax error
Error

Line: 41

              
const static NamespaceString kNs("db.dummyNs");

TEST_F(QueryPlannerTest, PartialIndexEq) {
    params.options = QueryPlannerParams::NO_TABLE_SCAN;
    BSONObj filterObj(fromjson("{a: {$gt: 0}}"));
    std::unique_ptr<MatchExpression> filterExpr = parseMatchExpression(filterObj);
    addIndex(fromjson("{a: 1}"), filterExpr.get());


            

Reported by Cppcheck.

src/mongo/db/query/query_planner_text_test.cpp
1 issues
syntax error
Error

Line: 52

              //

// Basic test that it works.
TEST_F(QueryPlannerTest, SimpleText) {
    addIndex(BSON("_fts"
                  << "text"
                  << "_ftsx" << 1));
    runQuery(fromjson("{$text: {$search: 'blah'}}"));


            

Reported by Cppcheck.

src/mongo/db/query/query_planner_tree_test.cpp
1 issues
syntax error
Error

Line: 55

                      "{filter: null, pattern: {x: 1}}}}}");
}

TEST_F(QueryPlannerTest, SimpleOr) {
    addIndex(BSON("a" << 1));
    runQuery(fromjson("{$or: [{a: 20}, {a: 21}]}"));

    ASSERT_EQUALS(getNumSolutions(), 2U);
    assertSolutionExists("{cscan: {dir: 1, filter: {a: {$in: [20, 21]}}}}");

            

Reported by Cppcheck.

src/mongo/db/query/query_planner_wildcard_index_test.cpp
1 issues
syntax error
Error

Line: 98

              // General planning tests.
//

DEATH_TEST_F(QueryPlannerWildcardTest, CannotExpandPreExpandedWildcardIndexEntry, "Invariant") {
    addWildcardIndex(BSON("$**" << 1));
    ASSERT_EQ(params.indices.size(), 2U);

    // Expand the $** index and add the expanded entry to the list of available indices.
    std::vector<IndexEntry> expandedIndex;

            

Reported by Cppcheck.

src/mongo/db/query/query_request_helper.cpp
1 issues
char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 115 Column: 17 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

                              // [ { a : ... } , { b : ... } ] -> { a : ..., b : ... }
                // note: this is slow, but that is ok as order will have very few pieces
                BSONObjBuilder b;
                char p[2] = "0";

                while (1) {
                    BSONObj j = findCommand->getSort().getObjectField(p);
                    if (j.isEmpty()) {
                        break;

            

Reported by FlawFinder.