[PATCH] D32700: [clang-tidy] Add bugprone-suspicious-memset-usage check.

Whisperity via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 12 05:05:51 PDT 2017


whisperity requested changes to this revision.
whisperity added a comment.
This revision now requires changes to proceed.

Considering the results published in the opening description:

/home/reka/codechecker_dev_env/llvm/lib/Support/NativeFormatting.cpp:55:29: <https://github.com/llvm-mirror/llvm/blob/master/lib/Support/NativeFormatting.cpp#L55> `warning: memset fill value is char '0', potentially mistaken for int 0 [bugprone-suspicious-memset-usage]`

  std::memset(NumberBuffer, '0', sizeof(NumberBuffer));
                            ^~~~
                            0

/home/reka/codechecker_dev_env/llvm/lib/Support/NativeFormatting.cpp:148:26: <https://github.com/llvm-mirror/llvm/blob/master/lib/Support/NativeFormatting.cpp#L148> `warning: memset fill value is char '0', potentially mistaken for int 0 [bugprone-suspicious-memset-usage]`

  ::memset(NumberBuffer, '0', llvm::array_lengthof(NumberBuffer));
                         ^~~~
                         0

In these case, the buffer is of `char[]` type. This `memset` call initialises the array with the character literal ASCII `0`, which is, in this context, the expected behaviour. Maybe you should add an exemption from the checker for these cases, i.e. where we **do** know that the buffer is a `char[]`.

Tests should be extended with a case for this addition.


https://reviews.llvm.org/D32700





More information about the cfe-commits mailing list