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

Open
#772 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
devtools

Research direction

Start with the implementations of rules A27-0-4 and A18-1-1, then reproduce the supplied C++ example. Compare the diagnostics for the macro, assert call, and stringized expression with cases that directly use arrays or strings. Done means the reported false positives are resolved while the affected rules still detect their intended cases.

Written by the indexing model from the issue text.

Description

false positive/false negative Standard-AUTOSAR
Affected rules
  • A27-0-4
  • A18-1-1
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");

Dominant language
CodeQL
Stars
227
Forks
82
Avg merge
6d 7h
Merged PRs (30d)
9

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from github/codeql-coding-standards

All issues in github/codeql-coding-standards

Similar issues

More DevTools issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.