nimble-code / Cobra

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

False positive: "Do not use dynamic memory allocation after task initialization" #25

Closed mjeronimo closed 3 years ago

mjeronimo commented 3 years ago

Using either the jpl or p10 rule sets, the following code erroneously generates the "Do not use dynamic memory after task initialization".

To reproduce:

cobra -C++ -comments -f jpl t1.c
cobra -C++ -comments -f p10 t1.c

Where t1.c is:

bool
rcutils_allocator_is_valid(const rcutils_allocator_t * allocator)
{
  if (
    NULL == allocator ||
    NULL == allocator->allocate ||
    NULL == allocator->deallocate ||
    NULL == allocator->zero_allocate ||
    NULL == allocator->reallocate)
  {
    return false;
  }
  return true;
}

The resulting output is:

=== R5: Do not use dynamic memory allocation after task initialization: 9
t1.c:6:
  1:      6      NULL == allocator ||
t1.c:7:
  2:      7      NULL == allocator->allocate ||
t1.c:8:
  3:      8      NULL == allocator->deallocate ||
t1.c:9:
  4:      9      NULL == allocator->zero_allocate ||
t1.c:10:
  5:     10      NULL == allocator->reallocate)
    globals used in one scope only:   0
    globals used in one file  only:   0
=== R16: Nr of statements: 2
=== R16: Nr of assertions: 0
=== R16: the minimum number of assertions is 2% = 0
1 errors
nimble-code commented 3 years ago

will update the query

nimble-code commented 3 years ago

fixed