github / codeql-coding-standards

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

`RULE-1-2`: False positives reported for variable length arrays #701

Closed lcartey closed 1 month ago

lcartey commented 2 months ago

Affected rules

Description

This rule currently flags all variable length arrays, and arrays without a specified size, but which are initialized. However, various types of variable length arrays are permitted in C99 onwards.

Example

void example_function(int n, int x[n]) { // COMPLIANT[FALSE_POSITIVE]
  struct S {
    int x1[n]; // NON_COMPLIANT
    int x2[]; // COMPLIANT[FALSE_POSITIVE]
  };

  int y[] = {1,2,3}; // COMPLIANT[FALSE_POSITIVE]
}