PVS-StudioWarnings

PVS-Studio warning V629 for Bitcoin

Nov 10th, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. static int64_t set_vch(const std::vector<unsigned char>& vch)
  2. {
  3.   if (vch.empty())
  4.     return 0;
  5.  
  6.   int64_t result = 0;
  7.   for (size_t i = 0; i != vch.size(); ++i)
  8.       result |= static_cast<int64_t>(vch[i]) << 8*i;
  9.  
  10.   // If the input vector's most significant byte is 0x80,
  11.   // remove it from the result's msb and return a negative.
  12.   if (vch.back() & 0x80)
  13.       return -(result & ~(0x80 << (8 * (vch.size() - 1))));
  14.  
  15.    return result;
  16. }
  17.  
  18. This suspicious code was found in Bitcoin project by PVS-Studio static code analyzer.
  19. Warning message is:
  20. V629 Consider inspecting the '0x80 << (8 * (vch.size() - 1))' expression. Bit shifting of the 32-bit value with a subsequent expansion to the 64-bit type. script.h 169
  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