From: Jiri Vlasak Date: Mon, 24 Jun 2019 15:14:55 +0000 (+0200) Subject: Fix indexing overflow X-Git-Tag: v0.7.0~5^2~6 X-Git-Url: https://rtime.felk.cvut.cz/gitweb/hubacji1/iamcar.git/commitdiff_plain/bac6f7ab59f4becbd78a5bb1418dd47f6fde3297 Fix indexing overflow --- diff --git a/base/rrtbase.cc b/base/rrtbase.cc index 97e4a5f..563fc04 100644 --- a/base/rrtbase.cc +++ b/base/rrtbase.cc @@ -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; }