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

nasa / trick / 22731392546

05 Mar 2026 06:36PM UTC coverage: 55.804%. First build
22731392546

Pull #1965

github

web-flow
Merge 8ca9f0443 into 43b8fa7c8
Pull Request #1965: 1964 methods return size one pointers

148 of 179 new or added lines in 3 files covered. (82.68%)

12624 of 22622 relevant lines covered (55.8%)

298214.24 hits per line

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

71.19
/trick_source/sim_services/MemoryManager/MemoryManager_get_attributes_for_address.cpp
1
#include "trick/MemoryManager.hh"
2
#include "trick/ClassicCheckPointAgent.hh"
3
#include "trick/AttributesUtils.hh"
4

5
static int getCompositeSubReference(
9✔
6
    size_t addrValue,
7
    ATTRIBUTES &attrOut,
8
    size_t structAddrValue,
9
    ATTRIBUTES *structAttr)
10
{
11
    if (addrValue < structAddrValue)
9✔
12
    {
NEW
13
        return 1;
×
14
    }
15

16
    size_t addrOffsetFromStruct = addrValue - structAddrValue;
9✔
17

18
    Trick::AttributesUtils::TraversalResult traversalResult;
19

20
    int ret = Trick::AttributesUtils::traverse_for_offset(addrOffsetFromStruct, structAttr, traversalResult);
9✔
21

22
    if (ret != 0)
9✔
23
    {
NEW
24
        return 1;
×
25
    }
26

27
    // Handle anonymous/**'d out members
28
    if (traversalResult.is_in_anonymous_member)
9✔
29
    {
NEW
30
        attrOut = ATTRIBUTES();
×
NEW
31
        attrOut.type = TRICK_VOID_PTR;
×
NEW
32
        attrOut.size = sizeof(void *);
×
NEW
33
        attrOut.offset = addrOffsetFromStruct;
×
NEW
34
        attrOut.num_index = 1;
×
NEW
35
        attrOut.index[0].size = 0;
×
36

NEW
37
        return 0;
×
38
    }
39

40
    ATTRIBUTES *retAttr = traversalResult.found_attr;
9✔
41

42
    // If the found attribute is a primitive type
43
    if (retAttr->type != TRICK_STRUCTURED)
9✔
44
    {
45
        // Scalar or pointer - return as unconstrained pointer
46
        if (retAttr->index[0].size == 0)
5✔
47
        {
48
            attrOut = *retAttr;
3✔
49
            attrOut.num_index = 1;
3✔
50
            attrOut.index[0].size = (retAttr->num_index == 0) ? 1 : 0;
3✔
51
            return 0;
3✔
52
        }
53

54
        // This is an array type. Calculate the offset from the address to the end of the attribute
55
        // Then, calculate the remaining elements in the array as a single value.
56
        // Calculate the maximum offset of this attribute.
57
        size_t max_offset = retAttr->size;
2✔
58
        for (int ii = 0; ii < retAttr->num_index; ii++)
5✔
59
        {
60
            if (retAttr->index[ii].size > 0)
3✔
61
            {
62
                max_offset *= retAttr->index[ii].size;
3✔
63
            }
64
        }
65

66
        attrOut = *retAttr;
2✔
67
        attrOut.num_index = 1;
2✔
68
        attrOut.index[0].size = (max_offset - traversalResult.offset_from_found_attr) / retAttr->size;
2✔
69
        return 0;
2✔
70
    }
71

72
    // If it is a reference type, do nothing and return
73
    if ((retAttr->mods & 1) == 1)
4✔
74
    {
NEW
75
        attrOut = *retAttr;
×
NEW
76
        return 0;
×
77
    }
78

79
    // If attribute is an unarrayed struct, continue to call getCompositeSubReference
80
    if (retAttr->num_index == 0)
4✔
81
    {
82
        return getCompositeSubReference(addrValue, attrOut, structAddrValue + retAttr->offset, (ATTRIBUTES *)retAttr->attr);
4✔
83
    }
84

85
    // If the member is a pointer, do nothing and return
NEW
86
    if (retAttr->index[0].size == 0)
×
87
    {
NEW
88
        attrOut = *retAttr;
×
NEW
89
        return 0;
×
90
    }
91

92
    // Arrayed struct - recurse into the element
NEW
93
    return getCompositeSubReference(addrValue, attrOut,
×
NEW
94
                                    structAddrValue + retAttr->offset + traversalResult.offset_from_found_attr,
×
NEW
95
                                    (ATTRIBUTES *)retAttr->attr);
×
96
}
97

98
/**
99
 @par Detailed Description:
100
 */
101
void Trick::MemoryManager::get_attributes_for_address(void *address, ATTRIBUTES &attrOut)
165✔
102
{
103
    /** Find the allocation that contains the pointer-address. */
104
    ALLOC_INFO *alloc_info = get_alloc_info_of(address);
165✔
105

106
    if (alloc_info != NULL)
165✔
107
    {
108
        // Found the allocation. Look for the attribute that pertains to it.
109
        size_t addrValue = reinterpret_cast<size_t>(address);
151✔
110
        size_t allocAddrStart = reinterpret_cast<size_t>(alloc_info->start);
151✔
111
        size_t alloc_elem_size = alloc_info->size;
151✔
112
        size_t alloc_elem_index = (addrValue - allocAddrStart) / alloc_elem_size;
151✔
113
        size_t misalignment = (addrValue - allocAddrStart) % alloc_elem_size;
151✔
114

115
        if (alloc_info->type == TRICK_STRUCTURED)
151✔
116
        {
117
            // The allocation is not a primitive type, traverse the structure unil the attribute is found or an
118
            // anonymous pointer is returned
119
            getCompositeSubReference(addrValue, attrOut, allocAddrStart + (alloc_elem_index * alloc_elem_size),
5✔
120
                                     alloc_info->attr);
121
        }
122
        else
123
        {
124
            // Primitive allocation is found, compute the remaining number of elements from the current address
125
            size_t allocAddrEnd = reinterpret_cast<size_t>(alloc_info->end) + 1;
146✔
126
            size_t max_alloc_index = (allocAddrEnd - allocAddrStart) / alloc_elem_size;
146✔
127
            if (alloc_info->attr)
146✔
128
            {
129
                // If there's an attribute for this allocation for some reason, populate the return structure.
130
                attrOut = *(alloc_info->attr);
8✔
131
            }
132
            attrOut.num_index = 1;
146✔
133
            attrOut.index[0].size = max_alloc_index - alloc_elem_index;
146✔
134
        }
135
    }
136
    else
137
    {
138
        // No allocation found, num_index = 0 should indicate that it's not found. On the swig, side, the calling
139
        // function will set num_index to 1 anyway and it becomes a generic pointer according to swig/python.
140
        attrOut = ATTRIBUTES();
14✔
141
    }
142
}
165✔
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