PVS-StudioWarnings

PVS-Studio warning V557 for MTASA

Nov 18th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.91 KB | None | 0 0
  1. enum ePools {
  2.     BUILDING_POOL = 0,
  3.     PED_POOL,
  4.     OBJECT_POOL,
  5.     DUMMY_POOL,
  6.     VEHICLE_POOL,
  7.     COL_MODEL_POOL,
  8.     TASK_POOL,
  9.     EVENT_POOL,
  10.     TASK_ALLOCATOR_POOL,
  11.     PED_INTELLIGENCE_POOL,
  12.     PED_ATTRACTOR_POOL,
  13.     ENTRY_INFO_NODE_POOL,
  14.     NODE_ROUTE_POOL,
  15.     PATROL_ROUTE_POOL,
  16.     POINT_ROUTE_POOL,
  17.     POINTER_DOUBLE_LINK_POOL,
  18.     POINTER_SINGLE_LINK_POOL,
  19.     ENV_MAP_MATERIAL_POOL,
  20.     ENV_MAP_ATOMIC_POOL,
  21.     SPEC_MAP_MATERIAL_POOL,
  22.     MAX_POOLS
  23. };
  24.  
  25. void CPoolsSA::DumpPoolsStatus ()
  26. {
  27.   char*  poolNames[] = {
  28.     "Buildings", "Peds", "Objects", "Dummies", "Vehicles",
  29.     "ColModels", "Tasks", "Events", "TaskAllocators",
  30.     "PedIntelligences", "PedAttractors", "EntryInfoNodes",
  31.     "NodeRoutes", "PatrolRoutes", "PointRoutes",
  32.     "PointerNodeDoubleLinks", "PointerNodeSingleLinks" };
  33.  
  34.     int poolSizes[] = {
  35.       13000,140,350,2500,110,10150,500,200,16,140,64,500,
  36.       64,32,64,3200,70000 };
  37.  
  38.     int iPosition = 0;
  39.     char percent = '%';
  40.     iPosition += snprintf ( szOutput, 1024,
  41.                             "-----------------\n" );
  42.     for ( int i = 0; i < MAX_POOLS; i++ )
  43.     {
  44.       int usedSpaces = GetNumberOfUsedSpaces ( (ePools)i );
  45.       iPosition +=
  46.         snprintf ( szOutput + iPosition, 1024 - iPosition,
  47.                    "%s: %d (%d) (%.2f%c)\n", poolNames[i],
  48.                    usedSpaces, poolSizes[i],
  49.                    ((float)usedSpaces/(float)poolSizes[i]*100),
  50.                    percent  );
  51.     }
  52.     #ifdef MTA_DEBUG
  53.     OutputDebugString ( szOutput );
  54.     #endif
  55. }
  56.  
  57. This suspicious code was found in MTASA project by PVS-Studio static code analyzer.
  58. Warning message is:
  59. V557 Array overrun is possible. The value of 'i' index could reach 19. cpoolssa.cpp 1036
  60.  
  61. 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