Skip to content

Commit 45c7a51

Browse files
authored
Merge pull request #22460 from MathiasVP/add-crazy-fp
C++: Fix a crazy FP in `cpp/leap-year/unsafe-array-for-days-of-the-year`
2 parents bc3447f + 416b3ee commit 45c7a51

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

cpp/ql/src/Likely Bugs/Leap Year/UnsafeArrayForDaysOfYear.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ where
2626
or
2727
exists(Variable var |
2828
var = element and
29+
not var.isCompilerGenerated() and
2930
var.getType() instanceof LeapYearUnsafeDaysOfTheYearArrayType and
3031
allocType = "an array allocation"
3132
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The `cpp/leap-year/unsafe-array-for-days-of-the-year` query ("Unsafe array for days of the year") no longer reports an alert on the `__PRETTY_FUNCTION__` variable (and related variables) when the enclosing function has a signature that is exactly 364 characters.

cpp/ql/test/query-tests/Likely Bugs/Leap Year/UnsafeArrayForDaysOfYear/test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,12 @@ void VectorOfDays_FalsePositive(int dayOfYear, int x)
6868

6969
items[dayOfYear - 1] = x;
7070
}
71+
72+
void f_______________________________________________________this_name_must_be_exactly_357_chars__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________() {
73+
// Using this magic compiler variable results in a `const char` array being
74+
// initialized with the function signature. Including `void`, a space, and
75+
// `()`, the signature adds up to exactly 364 characters in this case.
76+
// The initializer for `__PRETTY_FUNCTION__` thus initializes an array of
77+
// length 365 (because the null-terminator adds another character).
78+
auto x = __PRETTY_FUNCTION__; // clean
79+
}

0 commit comments

Comments
 (0)