github / codeql-coding-standards

This repository contains CodeQL queries and libraries which support various Coding Standards.
MIT License
129 stars 59 forks source link

`A27-0-4`: C-Style (and arrays) detected when logging in assert or using the hash/stringize operator in a macro #772

Open fjatWbyT opened 1 month ago

fjatWbyT commented 1 month ago

Affected rules

Description

Alerts of both rules are triggered even if no C-style array or string is directly used. It may also be relevant that the usage of the # operator is covered by rule M16-3-2.

Example

#include <cassert>

#define ASSERT(expr) ((expr) ? static_cast<void>(0) : [] { assert(false && #expr); }())

class a_class
{
  public:
    void some_operator()
    {
        ASSERT(flag_);
    }

  private:
    bool flag_ = false;
};

int main()
{
    assert((false) && "A way to add an assert message");
    a_class instance;
    instance.some_operator();
}

A27-0-4 and A18-1-1 alerts are signaled on ASSERT(flag_); as well as assert((false) && "A way ... message");