PVS-StudioWarnings

PVS-Studio warning V547 for MongoDB

Nov 11th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. inline const char * after(const char *s, char x);
  2. inline string after(const string& s, char x);
  3. inline const char * after(const char *s, const char *x);
  4. inline string after(string s, string x);
  5.  
  6. inline const char * after(const char *s, char x) {
  7.   const char *p = strchr(s, x);
  8.   return (p != 0) ? p+1 : "";
  9. }
  10.  
  11. int main() {
  12. {
  13.   ...
  14.   assert( str::after("abcde", 'x') == "" );
  15.   ...
  16. }
  17.  
  18. This suspicious code was found in MongoDB project by PVS-Studio static code analyzer.
  19. Warning message is:
  20. V547 Expression 'str::after("abcde", 'x') == ""' is always false. To compare strings you should use strcmp() function. test.cpp 43
  21.  
  22. PVS-Studio is a static analyzer for detecting bugs in the source code of applications written in C, C++, C++11, C++/CX. Site: http://www.viva64.com/en/pvs-studio/
Advertisement
Add Comment
Please, Sign In to add comment