memset

C++ quiz by PVS-Studio and Sergei Kushnirenko

The PVS-Studio team along with Sergei Kushnirenko prepared a quiz based on his publications about errors he found. Take the quiz, challenge your focus and coding skills while looking for errors in the C++ code. Attention! When taking the quiz, you may exclaim that some tasks are unfair. Indeed. However, please relax and approach them with humor. The quiz is just for fun.

C++ quiz by PVS-Studio and Sergei Kushnirenko

by Sergei Kushnirenko

About the quiz:

After taking the quiz, you may have questions about why this or that answer is marked as correct or incorrect. Welcome to the article: "Breaking down the C++ quiz by Sergei Kushnirenko" — here you will find answers to your questions.  Please read it only after you have puzzled over code snippets with errors and undefined behavior. Be sure — it will be more interesting.

Safe Clearing of Private Data

We often need to store private data in programs, for example passwords, secret keys, and their derivatives, and we usually need to clear their traces in the memory after using them so that a potential intruder can't gain access to these data. In this article we will discuss why you can't clear private data using memset() function.

Safe Clearing of Private Data

by Roman Fomichev

From the article:

So, both gcc and clang decided to optimize our code. Since the memory is freed after calling the memset() function, the compilers treat this call as irrelevant and delete it.