• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nasa / trick / 16179091313

09 Jul 2025 08:05PM UTC coverage: 55.919% (-0.03%) from 55.948%
16179091313

Pull #1922

github

web-flow
Merge 04a907d09 into d9a49c036
Pull Request #1922: Added a check for unconstrained dimensions boundary.

14 of 25 new or added lines in 3 files covered. (56.0%)

4 existing lines in 2 files now uncovered.

12334 of 22057 relevant lines covered (55.92%)

252313.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.18
/trick_source/sim_services/MemoryManager/MemoryManager_ref_dim.cpp
1
#include <stdio.h>
2
#include <sys/types.h>
3
#include <string.h>
4
#include <sstream>
5

6
#include "trick/MemoryManager.hh"
7
#include "trick/vval.h"
8
#include "trick/attributes.h"
9
#include "trick/reference.h"
10
#include "trick/parameter_types.h"
11

12
/*
13
 Updates R, a reference to an arrayed object, to a reference to the indexed sub-element of that arrayed object.
14
*/
15
int Trick::MemoryManager::ref_dim( REF2* R, V_DATA* V) {
21,744✔
16

17
    int jj;
18
    int item_size;
19
    int index_value = vval_int(V);
21,744✔
20

21
    if (R->ref_type != REF_ADDRESS) {
21,744✔
22
        emitError("Attempt to index into a non-address reference is bogus in ref_dim.") ;
×
23
        return (1);
×
24
    }
25

26
    R->num_index_left--;
21,744✔
27
    if (R->num_index_left < 0) {
21,744✔
28
        /* if we have too many dimensions, flag an error */
29
        emitError("Too many dimensions in ref_dim.\n") ;
×
30
        return (TRICK_PARAMETER_ARRAY_SIZE);
×
31
    }
32

33
    /*Calculate the size of the items in this array. */
34
    item_size =  R->attr->size;
21,744✔
35
    for (jj = (R->attr->num_index - 1); jj > R->num_index; jj--) {
23,087✔
36
        if (R->attr->index[jj].size > 0) {
1,343✔
37
            item_size *= R->attr->index[jj].size;
635✔
38
        } else {
39
            item_size = sizeof(void *);
708✔
40
            R->pointer_present = 1 ;
708✔
41
        }
42
    }
43

44
    /* if current dimension is a constrained ... */
45
    if (R->attr->index[R->num_index].size != 0) {
21,744✔
46

47
        /* for constrained dimensions, we can check the validity of the index value */
48
        if (index_value >= R->attr->index[R->num_index].size || index_value < 0) {
21,632✔
49
            /* print out of bounds error message if MM debug_level is greater than 1 */
50
            if (debug_level > 1) {
3✔
NEW
51
                emitError("Memory Manager ERROR: Array index out of bounds.") ;
×
52
            }
53
            return (TRICK_PARAMETER_ARRAY_SIZE);
3✔
54
        }
55

56
    } else {
57

58
        /* for unconstrained dimensions, we can check that the index value is non-negative
59
           and that it is less than the size of the array */
60
        if (index_value >= (get_size(*(void**)(R->address))) || index_value < 0) {
112✔
61
            /* print out of bounds error message if MM debug_level is greater than 1 */
NEW
62
            if (debug_level > 1) {
×
NEW
63
                std::stringstream message;
×
NEW
64
                message << index_value << " is out of bounds for " << R->reference << " (size=" << get_size(*(void**)(R->address)) << ").";
×
NEW
65
                emitError(message.str());
×
66
            }
NEW
67
            return (TRICK_PARAMETER_ARRAY_SIZE);
×
68
        }
69

70
        R->pointer_present = 1 ;
112✔
71
        if ( R->create_add_path ) {
112✔
72
            ADDRESS_NODE * address_node ;
73

74
            address_node = new ADDRESS_NODE ;
112✔
75
            address_node->operator_ = AO_DEREFERENCE ;
112✔
76
            address_node->operand.address = NULL ;
112✔
77
            DLL_AddTail(address_node , R->address_path) ;
112✔
78
        }
79

80
        // Dereference the pointer.
81
        R->address = *(void**)R->address;
112✔
82
        if ( R->address == NULL) {
112✔
83
            std::stringstream message;
×
84
            message << "Reference (" << R->reference << ") address is NULL in ref_dim.";
×
85
            emitError(message.str());
×
86
            return(TRICK_PARAMETER_ADDRESS_NULL) ;
×
87
        }
88
    }
89

90
    if ( R->create_add_path ) {
21,741✔
91

92
        ADDRESS_NODE * address_node ;
93

94
        if ( index_value > 0 ) {
9,798✔
95
            address_node = (ADDRESS_NODE *)DLL_GetAt(DLL_GetTailPosition(R->address_path), R->address_path) ;
9,191✔
96
            switch ( address_node->operator_ ) {
9,191✔
97
                case AO_ADDRESS:
9,079✔
98
                    address_node->operand.address = (void *)((char *)address_node->operand.address +  index_value * item_size) ;
9,079✔
99
                    break ;
9,079✔
100
                case AO_DEREFERENCE:
112✔
101
                    address_node = new ADDRESS_NODE ;
112✔
102
                    address_node->operator_ = AO_OFFSET ;
112✔
103
                    address_node->operand.offset = index_value * item_size ;
112✔
104
                    DLL_AddTail(address_node , R->address_path) ;
112✔
105
                    break ;
112✔
106
                case AO_OFFSET:
×
NEW
107
                    address_node->operand.offset += index_value * item_size ;
×
108
                    break ;
×
109
            }
110
        }
111
    }
112

113
    R->address =  (void*)((char*)R->address + index_value * item_size);
21,741✔
114
    R->num_index++;
21,741✔
115

116
    return (TRICK_NO_ERROR);
21,741✔
117
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc