From 7e81a238e04a7d3e07755535208321b8d2b87918 Mon Sep 17 00:00:00 2001 From: hsutter Date: Wed, 2 Dec 2015 12:36:23 -0800 Subject: [PATCH] Updated Bounds.4 as suggested in issue #267 --- CppCoreGuidelines.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index df0d85c..915dfbc 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -12692,17 +12692,23 @@ These functions all have bounds-safe overloads that take `span`. Standard types void f() { array a, b; - memset(a.data(), 0, 10); // BAD, and contains a length error - memcmp(a.data(), b.data(), 10); // BAD, and contains a length error + memset(a.data(), 0, 10); // BAD, and contains a length error (length = 10 * sizeof(int)) + memcmp(a.data(), b.data(), 10); // BAD, and contains a length error (length = 10 * sizeof(int)) } +Also, `std::array<>::fill()` or `std::fill()` or even an empty initializer are better candidate than `memset()`. + ##### Example, good void f() { - array a, b; - memset(a, 0); // OK - memcmp({a, b}); // OK + array a, b, c{}; // c is initialized to zero + a.fill(0); + fill(b.begin(), b.end(), 0); // std::fill() + fill(b, 0); // std::fill() + Ranges TS + + if ( a == b ) { + } } ##### Example