Skip to content

Commit 1b0fde1

Browse files
committed
Fix index-out-of-bounds exception
1 parent 5d3b120 commit 1b0fde1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ModelicaByExample/Functions/Interpolation/source/VectorTable.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ interpolateVectorTable(void *object, double x) {
7676
ModelicaFormatError("Requested value of x=%g is above the upper bound of %g\n",
7777
x, table->x[table->npoints-1]);
7878

79-
while(x>=table->x[i+1]) i = i + 1;
80-
while(x<table->x[i]) i = i - 1;
79+
while(i<table->npoints-1&&x>table->x[i+1]) i++;
80+
while(i>0&&x<table->x[i]) i--;
8181

8282
p = (x-table->x[i])/(table->x[i+1]-table->x[i]);
8383
table->lastIndex = i;

0 commit comments

Comments
 (0)