PVS-StudioWarnings

PVS-Studio warning V629 for smhasher

Nov 11th, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. __inline__ unsigned long long int rdtsc()
  2. {
  3. #ifdef __x86_64__
  4.   unsigned int a, d;
  5.   __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
  6.   return (unsigned long)a | ((unsigned long)d << 32);
  7. #elif defined(__i386__)
  8.   unsigned long long int x;
  9.   __asm__ volatile ("rdtsc" : "=A" (x));
  10.   return x;
  11. #else
  12. #define NO_CYCLE_COUNTER
  13.   return 0;
  14. #endif
  15. }
  16.  
  17. It may fail if the long type appears 32-bit - an overflow will occur in the "(unsigned long)d << 32" expression.
  18.  
  19. This suspicious code was found in smhasher project by PVS-Studio static code analyzer.
  20. Warning message is:
  21. V629 Consider inspecting the '(unsigned long) d << 32' expression. Bit shifting of the 32-bit value with a subsequent expansion to the 64-bit type. Platform.h 78
  22.  
  23. 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