mirror of
https://github.com/nasa/trick.git
synced 2025-06-20 16:10:28 +00:00
Fixed the way that Trick::MemoryManager::ref_dim() calculates the sizes of elements in an unconstrained array. Fixes #37.
This commit is contained in:
@ -29,43 +29,28 @@ int Trick::MemoryManager::ref_dim( REF2* R, V_DATA* V) {
|
|||||||
return (TRICK_PARAMETER_ARRAY_SIZE);
|
return (TRICK_PARAMETER_ARRAY_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if current dimension is a fixed dimension */
|
/*Calculate the size of the items in this array. */
|
||||||
if (R->attr->index[R->num_index].size != 0) {
|
item_size = R->attr->size;
|
||||||
|
for (jj = (R->attr->num_index - 1); jj > R->num_index; jj--) {
|
||||||
/* Set the size of the element we are going to parse */
|
if (R->attr->index[jj].size > 0) {
|
||||||
if (R->attr->index[(R->attr->num_index - 1)].size == 0) {
|
item_size *= R->attr->index[jj].size;
|
||||||
/* last dimension is a pointer, set item_size to sizeof pointer */
|
} else {
|
||||||
item_size = sizeof(void *);
|
item_size = sizeof(void *);
|
||||||
R->pointer_present = 1 ;
|
R->pointer_present = 1 ;
|
||||||
} else {
|
|
||||||
/* all dimensions are fixed, set item_size to sizeof element */
|
|
||||||
item_size = R->attr->size;
|
|
||||||
}
|
}
|
||||||
/* for fixed dimensions, we can check the validity of the index value */
|
}
|
||||||
|
|
||||||
|
/* if current dimension is a constrained ... */
|
||||||
|
if (R->attr->index[R->num_index].size != 0) {
|
||||||
|
|
||||||
|
/* for constrained dimensions, we can check the validity of the index value */
|
||||||
if (vval_int(V) >= R->attr->index[R->num_index].size || vval_int(V) < 0) {
|
if (vval_int(V) >= R->attr->index[R->num_index].size || vval_int(V) < 0) {
|
||||||
emitError("Memory Manager ERROR: Array index out of bounds.") ;
|
emitError("Memory Manager ERROR: Array index out of bounds.") ;
|
||||||
return (TRICK_PARAMETER_ARRAY_SIZE);
|
return (TRICK_PARAMETER_ARRAY_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* loop through all dimensions backwards, multiply the size of each dimension up to our current dimension
|
|
||||||
(R->num_index) */
|
|
||||||
for (jj = (R->attr->num_index - 1); jj > R->num_index; jj--) {
|
|
||||||
if (R->attr->index[jj].size > 0) {
|
|
||||||
item_size *= R->attr->index[jj].size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
R->pointer_present = 1 ;
|
|
||||||
|
|
||||||
// Current dimension is a pointer.
|
|
||||||
if (R->num_index == (R->attr->num_index - 1)) {
|
|
||||||
item_size = R->attr->size;
|
|
||||||
} else {
|
|
||||||
item_size = sizeof(void *);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( R->create_add_path ) {
|
if ( R->create_add_path ) {
|
||||||
ADDRESS_NODE * address_node ;
|
ADDRESS_NODE * address_node ;
|
||||||
|
|
||||||
@ -86,7 +71,7 @@ int Trick::MemoryManager::ref_dim( REF2* R, V_DATA* V) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( R->create_add_path ) {
|
if ( R->create_add_path ) {
|
||||||
|
|
||||||
ADDRESS_NODE * address_node ;
|
ADDRESS_NODE * address_node ;
|
||||||
|
|
||||||
if ( vval_int(V) > 0 ) {
|
if ( vval_int(V) > 0 ) {
|
||||||
|
Reference in New Issue
Block a user