github / codeql-coding-standards

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

`RULE-8-13`: Different compilations of the same variable #761

Closed lcartey closed 1 month ago

lcartey commented 1 month ago

Affected rules

Description

In cases where a piece of code is compiled multiple times in different contexts, a variable declaration may be written to in some contexts, but not others. In CodeQL, we store different copies of the Variable for the different contexts (so that they can be distinguished in our analysis). However, flagging one copy of a variable as missing const, when other copies cannot be marked as const, seems unreasonable.

Example

int test(int* x) { // COMPLIANT - written to in at least one context
#ifdef FOO
  x = 1;
#endif
  return x;
}