mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 08:36:06 +00:00

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
25 lines
466 B
C++
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}}
|
|
}
|