]>
Commit | Line | Data |
---|---|---|
2d6a38a5 | 1 | /* |
7c6a034c | 2 | * Copyright (C) 1996-2022 The Squid Software Foundation and contributors |
2d6a38a5 DC |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
9 | #ifndef SQUID_SRC_MEM_SENSITIVE_H | |
10 | #define SQUID_SRC_MEM_SENSITIVE_H | |
11 | ||
12 | #include <cstring> | |
13 | ||
14 | namespace Mem { | |
15 | ||
16 | /// zeros the given memory area while disallowing the compiler to skip (i.e. | |
17 | /// optimize away) this cleanup, unlike a regular call to std::memset() or alike | |
18 | inline void | |
19 | ZeroSensitiveMemory(void *dst, const size_t len) | |
20 | { | |
21 | if (!len) | |
22 | return; | |
23 | ||
24 | assert(dst); | |
25 | ||
26 | volatile const auto setMemory = &std::memset; | |
27 | (void)setMemory(dst, 0, len); | |
28 | } | |
29 | ||
30 | } // namespace mem | |
31 | ||
32 | #endif /* SQUID_SRC_MEM_SENSITIVE_H */ | |
33 |