Skip to content

Commit

Permalink
PVS/V1051: Ignore "modulo by 1" warning for ARRAY_SIZE. (neovim#14943)
Browse files Browse the repository at this point in the history
The warning is triggered by the second division when arr is a char array
since sizeof(char) is 1. A modulo by 1 may normally indicate a logic
error, but in this case it's intended.
  • Loading branch information
dundargoc authored Jul 3, 2021
1 parent 05330ba commit 70223ba
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/nvim/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@
/// error. A mechanism to detect many (though not all) of those errors at
/// compile time is implemented. It works by the second division producing
/// a division by zero in those cases (-Wdiv-by-zero in GCC).
///
/// -V:ARRAY_SIZE:1063
#define ARRAY_SIZE(arr) \
((sizeof(arr)/sizeof((arr)[0])) \
/ ((size_t)(!(sizeof(arr) % sizeof((arr)[0])))))
Expand Down

0 comments on commit 70223ba

Please sign in to comment.