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

nasa / trick / 23954964071

03 Apr 2026 05:14PM UTC coverage: 55.983% (+0.2%) from 55.798%
23954964071

Pull #1965

github

web-flow
Merge 1996fafff into d1ee90d41
Pull Request #1965: 1964 methods return size one pointers

173 of 205 new or added lines in 5 files covered. (84.39%)

73 existing lines in 2 files now uncovered.

12678 of 22646 relevant lines covered (55.98%)

295104.87 hits per line

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

69.35
/trick_source/sim_services/MemoryManager/MemoryManager_get_attributes_for_address.cpp
1
#include  <string.h>
2

3
#include "trick/MemoryManager.hh"
4
#include "trick/ClassicCheckPointAgent.hh"
5
#include "trick/AttributesUtils.hh"
6

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

19
    size_t addrOffsetFromStruct = addrValue - structAddrValue;
2,199✔
20

21
    Trick::AttributesUtils::TraversalResult traversalResult;
2,199✔
22

23
    int ret = Trick::AttributesUtils::traverse_for_offset(addrOffsetFromStruct, structAttr, traversalResult);
2,199✔
24
    remainingOffset = traversalResult.offset_from_found_attr;
2,199✔
25

26
    if (ret != 0)
2,199✔
27
    {
NEW
28
        return 1;
×
29
    }
30

31
    // Handle anonymous/**'d out members
32
    if (traversalResult.is_in_anonymous_member)
2,199✔
33
    {
NEW
34
        attrOut = ATTRIBUTES();
×
NEW
35
        attrOut.type = TRICK_VOID_PTR;
×
NEW
36
        attrOut.size = sizeof(void *);
×
NEW
37
        attrOut.offset = addrOffsetFromStruct;
×
NEW
38
        attrOut.num_index = 1;
×
NEW
39
        attrOut.index[0].size = 0;
×
40

NEW
41
        return 0;
×
42
    }
43

44
    ATTRIBUTES *retAttr = traversalResult.found_attr;
2,199✔
45

46
    // If the found attribute is a primitive type
47
    if (retAttr->type != TRICK_STRUCTURED)
2,199✔
48
    {
49
        // Scalar or pointer - return as unconstrained pointer
50
        if (retAttr->index[0].size == 0)
1,245✔
51
        {
52
            attrOut = *retAttr;
11✔
53
            attrOut.num_index = 1;
11✔
54
            attrOut.index[0].size = (retAttr->num_index == 0) ? 1 : 0;
11✔
55
            return 0;
11✔
56
        }
57

58
        attrOut = *retAttr;
1,234✔
59
        return 0;
1,234✔
60
    }
61

62
    // If it is a reference type, do nothing and return
63
    if ((retAttr->mods & 1) == 1)
954✔
64
    {
NEW
65
        attrOut = *retAttr;
×
NEW
66
        return 0;
×
67
    }
68

69
    // If attribute is an unarrayed struct, continue to call getCompositeSubReference
70
    if (retAttr->num_index == 0)
954✔
71
    {
72
        return getCompositeSubReference(addrValue, attrOut, structAddrValue + retAttr->offset, (ATTRIBUTES *)retAttr->attr, remainingOffset);
954✔
73
    }
74

75
    // If the member is a pointer, do nothing and return
NEW
76
    if (retAttr->index[0].size == 0)
×
77
    {
NEW
78
        attrOut = *retAttr;
×
NEW
79
        return 0;
×
80
    }
81

82
    // Arrayed struct - recurse into the element
NEW
83
    return getCompositeSubReference(addrValue, attrOut,
×
NEW
84
                                    structAddrValue + retAttr->offset + traversalResult.offset_from_found_attr,
×
NEW
85
                                    (ATTRIBUTES *)retAttr->attr, remainingOffset);
×
86
}
87

88
/**
89
 @par Detailed Description:
90
 */
91
void Trick::MemoryManager::get_attributes_for_address(void *address, ATTRIBUTES &attrOut, size_t & remainingOffset)
1,700✔
92
{
93
    if(address == nullptr)
1,700✔
94
    {
95
        attrOut = ATTRIBUTES();
42✔
96
        return;
42✔
97
    }
98

99
    /** Find the allocation that contains the pointer-address. */
100
    ALLOC_INFO *alloc_info = get_alloc_info_of(address);
1,658✔
101

102
    if (alloc_info != NULL)
1,658✔
103
    {
104
        // Found the allocation. Look for the attribute that pertains to it.
105
        size_t addrValue = reinterpret_cast<size_t>(address);
1,658✔
106
        size_t allocAddrStart = reinterpret_cast<size_t>(alloc_info->start);
1,658✔
107
        remainingOffset = addrValue - allocAddrStart;
1,658✔
108
        size_t alloc_elem_size = alloc_info->size;
1,658✔
109
        size_t alloc_elem_index = (addrValue - allocAddrStart) / alloc_elem_size;
1,658✔
110
        // size_t misalignment = (addrValue - allocAddrStart) % alloc_elem_size;
111

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