]> rtime.felk.cvut.cz Git - hubacji1/iamcar.git/commitdiff
Fix indexing overflow
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Mon, 24 Jun 2019 15:14:55 +0000 (17:14 +0200)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Mon, 24 Jun 2019 15:15:27 +0000 (17:15 +0200)
base/rrtbase.cc

index 97e4a5f1d354eff8d72141dfdef8b653c5e2f99d..563fc04d8364c3c99da74f1f2646b750985bc581 100644 (file)
@@ -1046,6 +1046,8 @@ int RRTBase::XI(RRTNode *n)
 {
         float step = (this->HMAX - this->HMIN) / IXSIZE;
         float index = (int) (floor(n->x() - this->HMIN) / step);
+        if (index < 0) index = 0;
+        if (index >= IXSIZE) index = IXSIZE - 1;
         return index;
 }
 
@@ -1053,6 +1055,8 @@ int RRTBase::YI(RRTNode *n)
 {
         float step = (this->VMAX - this->VMIN) / IYSIZE;
         float index = (int) (floor(n->y() - this->VMIN) / step);
+        if (index < 0) index = 0;
+        if (index >= IYSIZE) index = IYSIZE - 1;
         return index;
 }