Skip to content

Commit

Permalink
Add bounds checking of array access during runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund authored and perost committed Jan 20, 2020
1 parent 80b40a6 commit 6fa1e68
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions OMCompiler/SimulationRuntime/c/util/integer_array.c
Expand Up @@ -536,6 +536,9 @@ modelica_integer* integer_array_element_addr1(const integer_array_t * source,

modelica_integer* integer_array_element_addr2(const integer_array_t * source,int ndims,int dim1,int dim2)
{
if (dim1 < 1 || dim1 > source->dim_size[0] || dim2 < 1 || dim2 > source->dim_size[1]) {
throwStreamPrint(NULL, "integer_array_element_addr2: array has dimensions [%d,%d], got subscripts [%d,%d]", source->dim_size[1], source->dim_size[2], dim1, dim2);
}
return integer_ptrget(source, ((dim1 - 1) * source->dim_size[1]) + (dim2 - 1));
}

Expand Down
3 changes: 3 additions & 0 deletions OMCompiler/SimulationRuntime/c/util/real_array.c
Expand Up @@ -522,6 +522,9 @@ modelica_real* real_array_element_addr1(const real_array_t * source,int ndims,in

modelica_real* real_array_element_addr2(const real_array_t * source,int ndims,int dim1,int dim2)
{
if (dim1 < 1 || dim1 > source->dim_size[0] || dim2 < 1 || dim2 > source->dim_size[1]) {
throwStreamPrint(NULL, "real_array_element_addr2: array has dimensions [%d,%d], got subscripts [%d,%d]", source->dim_size[1], source->dim_size[2], dim1, dim2);
}
return real_ptrget(source, ((dim1 - 1) * source->dim_size[1]) + (dim2 - 1));
}

Expand Down

0 comments on commit 6fa1e68

Please sign in to comment.