]> granicus.if.org Git - clang/commit
[Sema] Add sizeof diagnostics for bzero
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Thu, 4 Aug 2016 23:55:22 +0000 (23:55 +0000)
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Thu, 4 Aug 2016 23:55:22 +0000 (23:55 +0000)
commitcab7b600139f46adb9b1dd553da3c941c2bf8e13
tree25ae0a781915d01c0024a321cb63aa33c99eb4c3
parent56699d4cc30bec4ac9e556a6885fa888890ac87c
[Sema] Add sizeof diagnostics for bzero

For memset (and others) we can get diagnostics like:

  struct stat { int x; };
  void foo(struct stat *stamps) {
    bzero(stamps, sizeof(stamps));
    memset(stamps, 0, sizeof(stamps));
  }

  t.c:7:28: warning: 'memset' call operates on objects of type 'struct stat' while the size is based on a different type 'struct stat *' [-Wsizeof-pointer-memaccess]
    memset(stamps, 0, sizeof(stamps));
           ~~~~~~            ^~~~~~
  t.c:7:28: note: did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)?
    memset(stamps, 0, sizeof(stamps));
                             ^~~~~~

This patch implements the same class of warnings for bzero.

Differential Revision: https://reviews.llvm.org/D22525

rdar://problem/18963514

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@277787 91177308-0d34-0410-b5e6-96231b3b80d8
lib/AST/Decl.cpp
lib/Sema/SemaChecking.cpp
test/SemaCXX/warn-memset-bad-sizeof.cpp