PVS-StudioWarnings

PVS-Studio warning V522 for Scilab

Nov 13th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. inline static int *alloc(void * pvApiCtx, const int position,
  2.   const int rows, const int cols, int * ptr)
  3. {
  4.   int * _ptr = 0;
  5.   SciErr err = allocMatrixOfInteger32(
  6.     pvApiCtx, position, rows, cols, &_ptr);
  7.   checkError(err);
  8.   return _ptr;
  9. }
  10.  
  11. inline static void create(void * pvApiCtx, const int position,
  12.   const int rows, const int cols, long long * ptr)
  13. {
  14.   int * dataPtr = 0;
  15.   alloc(pvApiCtx, position, rows, cols, dataPtr);
  16.   for (int i = 0; i < rows * cols; i++)
  17.   {
  18.     dataPtr[i] = static_cast<int>(ptr[i]);
  19.   }
  20. }
  21.  
  22. This is what should have been written here: dataPtr = alloc(pvApiCtx, position, rows, cols, dataPtr);
  23.  
  24.  
  25. This suspicious code was found in Scilab project by PVS-Studio static code analyzer.
  26. Warning message is:
  27. V522 Dereferencing of the null pointer 'dataPtr' might take place. scilababstractmemoryallocator.hxx 222
  28.  
  29. 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