Revision: 9122
          http://sourceforge.net/p/playerstage/svn/9122
Author:   jpgr87
Date:     2013-01-31 02:33:03 +0000 (Thu, 31 Jan 2013)
Log Message:
-----------
Fix off-by-one errors in ranger boundary checking

When accessing an array in the RangerProxy class (e.g. the ranges array), a
check is made to see if the number of elements in the array is grater than
the index being requested.  If the array had 0 elements (was unallocated), and
a request was made for the 0th element, this test passed and an unallocated
array was accessed.

This commit fixes the off-by-one error; you can only ever get index (length-1)
in any of the RangerProxy's array accesses.

Modified Paths:
--------------
    code/player/trunk/client_libs/libplayerc++/rangerproxy.cc

Modified: code/player/trunk/client_libs/libplayerc++/rangerproxy.cc
===================================================================
--- code/player/trunk/client_libs/libplayerc++/rangerproxy.cc   2013-01-12 
20:06:07 UTC (rev 9121)
+++ code/player/trunk/client_libs/libplayerc++/rangerproxy.cc   2013-01-31 
02:33:03 UTC (rev 9122)
@@ -85,35 +85,35 @@
 
 player_pose3d_t RangerProxy::GetElementPose(uint32_t aIndex) const
 {
-  if (aIndex > mDevice->element_count)
+  if (aIndex >= mDevice->element_count)
     throw PlayerError("RangerProxy::GetSensorPose", "index out of bounds");
   return GetVar(mDevice->element_poses[aIndex]);
 }
 
 player_bbox3d_t RangerProxy::GetElementSize(uint32_t aIndex) const
 {
-  if (aIndex > mDevice->element_count)
+  if (aIndex >= mDevice->element_count)
     throw PlayerError("RangerProxy::GetSensorSize", "index out of bounds");
   return GetVar(mDevice->element_sizes[aIndex]);
 }
 
 double RangerProxy::GetRange(uint32_t aIndex) const
 {
-  if (aIndex > mDevice->ranges_count)
+  if (aIndex >= mDevice->ranges_count)
     throw PlayerError("RangerProxy::GetRange", "index out of bounds");
   return GetVar(mDevice->ranges[aIndex]);
 }
 
 player_point_3d_t RangerProxy::GetPoint(uint32_t aIndex) const
 {
-  if (aIndex > mDevice->points_count)
+  if (aIndex >= mDevice->points_count)
     throw PlayerError("RangerProxy::GetPoint", "index out of bounds");
   return GetVar(mDevice->points[aIndex]);
 }
 
 double RangerProxy::GetIntensity(uint32_t aIndex) const
 {
-  if (aIndex > mDevice->intensities_count)
+  if (aIndex >= mDevice->intensities_count)
     throw PlayerError("RangerProxy::GetIntensity", "index out of bounds");
   return GetVar(mDevice->intensities[aIndex]);
 }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
Playerstage-commit mailing list
Playerstage-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to