nimble-code / Cobra

An interactive (fast) static source code analyzer
139 stars 31 forks source link

Cobra hangs on a simple test file #56

Closed Ronoman closed 1 year ago

Ronoman commented 1 year ago

Setup

Create a file named test_code.cpp (or something similar) with the following contents:

// Expect A16_0_1
#ifdef SOME_VAR
#define SOME_OTHER_VAR 5
#endif

// Expect another A16_1_1
#ifdef SOMETHING
#define SOMETHING_ELSE 10
#endif

int main(int argc, char *argv[]) {
    // Expect A18_1_1
    int my_arr[1024];

    // Expect another A18_1_1
    char some_buf[256];
}

This is obviously nonsense code, but it reproduces these issues for me.

Execution

Run /path/to/cobra -C++ -comments -json -f C++/autosar /path/to/test_code.cpp, replacing /path/to with the real absolute paths to the cobra binary and test_code.cpp files, respectively.

Expected result

Cobra outputs some issues to stdout, and reports them in various output files.

Actual result

The execution of the cobra binary hangs indefinitely.

Ronoman commented 1 year ago

Simplified test cases.

This source file will cause Cobra to hang:

#ifdef SOME_VAR
#define SOME_OTHER_VAR 5
#endif

int main(int argc, char *argv[]) {}

while this source file will be processed fine:

#ifdef SOME_VAR
#endif

int main(int argc, char *argv[]) {}
nimble-code commented 1 year ago

darn -- will look into it

nimble-code commented 1 year ago

fixed -- it was a mistake in the implementation of rule A5_1_1 thanks for reporting this