Bug 1879449 [wpt PR 44489] - [wptrunner] Add `infrastructure/expected-fail/` test...
[gecko.git] / tools / clang-tidy / test / bugprone-suspicious-memset-usage.cpp
blob71fe7239a1e4e35bc4192521aba93a874a4c7392
1 // https://clang.llvm.org/extra/clang-tidy/checks/bugprone-suspicious-memset-usage.html
3 #include "structures.h"
5 void test(int* ip, char* cp)
7 // Case 1: Fill value is a character '0' instead of NUL '\0'.
8 memset(ip, '0', 1); // WARNING: suspicious for non-char pointers
9 memset(cp, '0', 1); // OK for char pointers
11 // Case 2: Fill value is truncated.
12 memset(ip, 0xabcd, 1); // WARNING: fill value gets truncated
13 memset(ip, 0x00cd, 1); // OK because value 0xcd is not truncated.
14 memset(ip, 0x00, 1); // OK because value is not truncated.
16 // Case 3: Byte count is zero.
17 memset(ip, sizeof(int), 0); // WARNING: zero length, potentially swapped
18 memset(ip, sizeof(int), 1); // OK with non-zero length
20 // See clang bug https://bugs.llvm.org/show_bug.cgi?id=38098
21 memset(ip, 8, 0); // OK with zero length without sizeof