mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-17 12:44:42 +03:00
* ES.103 examples updated, addresses Issue #1656 * Fix cpplint report: Res-overflow0.cpp:18: Missing spaces around <= [whitespace/operators] [3]
This commit is contained in:
@@ -13200,22 +13200,21 @@ Incrementing a value beyond a maximum value can lead to memory corruption and un
|
|||||||
##### Example, bad
|
##### Example, bad
|
||||||
|
|
||||||
int a[10];
|
int a[10];
|
||||||
a[10] = 7; // bad
|
a[10] = 7; // bad, array bounds overflow
|
||||||
|
|
||||||
int n = 0;
|
for (int n = 0; n <= 10; ++n)
|
||||||
while (n++ < 10)
|
a[n] = 9; // bad, array bounds overflow
|
||||||
a[n - 1] = 9; // bad (twice)
|
|
||||||
|
|
||||||
##### Example, bad
|
##### Example, bad
|
||||||
|
|
||||||
int n = numeric_limits<int>::max();
|
int n = numeric_limits<int>::max();
|
||||||
int m = n + 1; // bad
|
int m = n + 1; // bad, numeric overflow
|
||||||
|
|
||||||
##### Example, bad
|
##### Example, bad
|
||||||
|
|
||||||
int area(int h, int w) { return h * w; }
|
int area(int h, int w) { return h * w; }
|
||||||
|
|
||||||
auto a = area(10'000'000, 100'000'000); // bad
|
auto a = area(10'000'000, 100'000'000); // bad, numeric overflow
|
||||||
|
|
||||||
##### Exception
|
##### Exception
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user