From 373f4c4808f1e40ba534d1df184828e67c3a8a37 Mon Sep 17 00:00:00 2001 From: Chris Guzak Date: Tue, 13 Mar 2018 15:28:26 -0700 Subject: [PATCH] use sizeof(buffer) instead of MAX --- CppCoreGuidelines.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 2db8b22..3c4ab4e 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -1584,7 +1584,7 @@ Consider a famous security bug: { char buffer[MAX]; // ... - memset(buffer, 0, MAX); + memset(buffer, 0, sizeof(buffer)); } There was no postcondition stating that the buffer should be cleared and the optimizer eliminated the apparently redundant `memset()` call: @@ -1593,7 +1593,7 @@ There was no postcondition stating that the buffer should be cleared and the opt { char buffer[MAX]; // ... - memset(buffer, 0, MAX); + memset(buffer, 0, sizeof(buffer)); Ensures(buffer[0] == 0); }