Advertisement
PVS-StudioWarnings

PVS-Studio warning V512 for Micro-Manager

Nov 10th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. typedef struct _DCMOTSTATUS
  2. {
  3.   unsigned short wChannel;   // Channel ident.
  4.   unsigned int lPosition;    // Position in encoder counts.
  5.   unsigned short wVelocity;  // Velocity in encoder counts/sec.
  6.   unsigned short wReserved;  // Controller specific use
  7.   unsigned int dwStatusBits; // Status bits (see #defines below).
  8. } DCMOTSTATUS;
  9.  
  10. int MotorStage::ParseStatus(const unsigned char* buf, int bufLen,
  11.   DCMOTSTATUS& stat)
  12. {
  13.   ....
  14.   memcpy(&stat.lPosition, buf + bufPtr, sizeof(long));  //<<<(1)
  15.   bufPtr += sizeof(long);
  16.  
  17.   memcpy(&stat.wVelocity, buf + bufPtr, sizeof(unsigned short));
  18.   bufPtr += sizeof(unsigned short);
  19.  
  20.   memcpy(&stat.wReserved, buf + bufPtr, sizeof(unsigned short));
  21.   bufPtr += sizeof(unsigned short);
  22.  
  23.   memcpy(&stat.dwStatusBits,
  24.          buf + bufPtr, sizeof(unsigned long));          //<<<(2)
  25.   return DEVICE_OK;
  26. }
  27.  
  28. (1) - Not critical. (2) - Critical.
  29.  
  30. This suspicious code was found in Micro-Manager project by PVS-Studio static code analyzer.
  31. Warning message is:
  32. V512 A call of the 'memcpy' function will lead to overflow of the buffer '& stat.lPosition'. MotorStage.cpp 247
  33.  
  34. 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
Advertisement