llvm-project/clang/test/Analysis/Issue56873.cpp
isuckatcs a46154cb1c [analyzer] Warn if the size of the array in new[] is undefined
This patch introduces a new checker, called NewArraySize checker,
which detects if the expression that yields the element count of
the array in new[], results in an Undefined value.

Differential Revision: https://reviews.llvm.org/D131299
2022-09-04 23:06:58 +02:00

25 lines
466 B
C++

// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection -verify %s
void clang_analyzer_warnIfReached();
struct S {
};
void Issue56873_1() {
int n;
// This line used to crash
S *arr = new S[n];
clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
}
void Issue56873_2() {
int n;
// This line used to crash
int *arr = new int[n];
clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
}