Skip to content

M0-1-10: Functions called from int32_t main() are not considered as "called" #646

Closed
@rak3-sh

Description

@rak3-sh

Affected rules

  • M0-1-10

Description

The class MainFunction defined in EncapsulatingFunctions.qll doesn't consider int32_t main() as a "main" function. Due to this, multiple false positives get raised in case the user has defined main with int32_t return type.

Example

Definitions of func1 and func2 are left out for reasons of brevity.

namespace mains {
    static int32_t var;

    // @brief namespace_func
    static void namespace_func(void) noexcept { // FP: Function is reported as not called, but it is called from "main" below.
        mains::var = -1;
        return;
    }
}  // namespace

// @brief main
// @return exit code
int32_t main(void) {
    int32_t ret {0};
    try {
        ret = func1(); // FP: Reported as not called in the definition location
        mains::var += ret;
        ret = func2(); // FP: Reported as not called in the definition location
        mains::var += ret;
    }
    catch(...) { 
        mains::namespace_func(); // namespace_func is called here.
    }
    return ret; 
}

Metadata

Metadata

Assignees

Labels

Difficulty-LowA false positive or false negative report which is expected to take <1 day effort to addressImpact-Lowfalse positive/false negativeAn issue related to observed false positives or false negatives.user-reportIssue reported by an end user of CodeQL Coding Standards

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions