xref: /llvm-project/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-memory-comparison.rst (revision 3cf574da407b9be01cc86f0ad2902c5d2ff8f078)
1.. title:: clang-tidy - bugprone-suspicious-memory-comparison
2
3bugprone-suspicious-memory-comparison
4=====================================
5
6Finds potentially incorrect calls to ``memcmp()`` based on properties of the
7arguments. The following cases are covered:
8
9**Case 1: Non-standard-layout type**
10
11Comparing the object representations of non-standard-layout objects may not
12properly compare the value representations.
13
14**Case 2: Types with no unique object representation**
15
16Objects with the same value may not have the same object representation.
17This may be caused by padding or floating-point types.
18
19See also:
20`EXP42-C. Do not compare padding data
21<https://wiki.sei.cmu.edu/confluence/display/c/EXP42-C.+Do+not+compare+padding+data>`_
22and
23`FLP37-C. Do not use object representations to compare floating-point values
24<https://wiki.sei.cmu.edu/confluence/display/c/FLP37-C.+Do+not+use+object+representations+to+compare+floating-point+values>`_
25
26This check is also related to and partially overlaps the CERT C++ Coding Standard rules
27`OOP57-CPP. Prefer special member functions and overloaded operators to C Standard Library functions
28<https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP57-CPP.+Prefer+special+member+functions+and+overloaded+operators+to+C+Standard+Library+functions>`_
29and
30`EXP62-CPP. Do not access the bits of an object representation that are not part of the object's value representation
31<https://wiki.sei.cmu.edu/confluence/display/cplusplus/EXP62-CPP.+Do+not+access+the+bits+of+an+object+representation+that+are+not+part+of+the+object%27s+value+representation>`_
32
33`cert-exp42-c` redirects here as an alias of this check.
34