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

nasa / trick / 44798765089

20 Nov 2026 07:04PM UTC coverage: 57.266% (+0.05%) from 57.215%
44798765089

push

github

web-flow
fix: resolve buffer overrun, double unlock, and queue cursor bugs in sim services (#2282)

4 of 6 new or added lines in 2 files covered. (66.67%)

15148 of 26452 relevant lines covered (57.27%)

490669.6 hits per line

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

72.22
/trick_source/sim_services/Integrator/src/Integrator.cpp
1
#include "trick/Integrator.hh"
2
#include "trick/message_proto.h"
3
#include "trick/message_type.h"
4
#include <cstdarg>
5
#include <iostream>
6

7
/**
8
 */
9
Trick::Integrator::Integrator() {
54 ✔
10

11
   num_state = 0;
54 ✔
12
   first_step_deriv = 1;
54 ✔
13
   last_step_deriv  = 0;
54 ✔
14
   intermediate_step = 0;
54 ✔
15
   is_2nd_order_ODE_technique = 0;
54 ✔
16
   use_deriv2 = 0;
54 ✔
17
   dt = 0.01;
54 ✔
18
   target_integ_time = dt;
54 ✔
19
   state = NULL;
54 ✔
20
   deriv = NULL;
54 ✔
21
   deriv2 = NULL;
54 ✔
22
   state_ws = NULL;
54 ✔
23
#ifndef USE_ER7_UTILS_INTEGRATORS
24
   state_origin = NULL;
25
#endif
26
   time = 0.0;
54 ✔
27
   time_0 = 0.0;
54 ✔
28
   verbosity = 0 ;
54 ✔
29
}
54 ✔
30

31
/**
32
 */
33
int Trick::Integrator::integrate_1st_order_ode (
×
34
    double const* derivs_in, double* state_in_out) {
35
    int rc;
36

37
    if (is_2nd_order_ODE_technique) {
×
38
        message_publish(MSG_ERROR,
×
39
                        "Integrator ERROR: "
40
                        "Current integrator is a 2nd order technique.\n");
41
        return 0;
×
42
    }
43

44
    for (int ii = 0; ii < num_state; ++ii) {
×
45
        state[ii] = state_in_out[ii];
×
46
        deriv[intermediate_step][ii] = derivs_in[ii];
×
47
    }
48

49
    rc = integrate ();
×
50

51
    for (int ii = 0; ii < num_state; ++ii) {
×
52
        state_in_out[ii] = state_ws[intermediate_step][ii];
×
53
    }
54

55
    return rc;
×
56
}
57

58
/**
59
 */
60
int Trick::Integrator::integrate_2nd_order_ode (
×
61
    double const* accel, double* velocity, double* position) {
62
    int rc;
63
    int half_size = num_state / 2;
×
64

65
    if (use_deriv2) {
×
66
        for (int ii = 0; ii < half_size; ++ii) {
×
67
            state[ii] = position[ii];
×
68
            deriv[intermediate_step][ii]  = velocity[ii];
×
69
            deriv2[intermediate_step][ii] = accel[ii];
×
70
        }
71
    }
72

73
    else {
74
        for (int ii = 0; ii < half_size; ++ii) {
×
75
            state[ii]           = position[ii];
×
76
            state[ii+half_size] = velocity[ii];
×
77
            deriv[intermediate_step][ii]           = velocity[ii];
×
78
            deriv[intermediate_step][ii+half_size] = accel[ii];
×
79
        }
80
    }
81

82
    rc = integrate ();
×
83

84
    for (int ii = 0; ii < half_size; ++ii) {
×
85
        position[ii] = state_ws[intermediate_step][ii];
×
86
        velocity[ii] = state_ws[intermediate_step][ii+half_size];
×
87
    }
88

89
    return rc;
×
90
}
91

92
void Trick::Integrator::state_reset () {
×
93
#ifdef USE_ER7_UTILS_INTEGRATORS
94
#else
95
    if (intermediate_step == 0) {
96

97
        if (verbosity) message_publish(MSG_DEBUG, "STATE RESET");
98
        for (int i=0; i<num_state ; i++) {
99
            *state_origin[i] = state[i];
100
        }
101
    }
102
#endif
103
}
×
104

105
#ifdef USE_ER7_UTILS_INTEGRATORS
106
void Trick::Integrator::state_in (double* arg1, va_list argp) {
39,247,585 ✔
107
    int i = 0;
39,247,585 ✔
108
    double* next_arg = arg1;
39,247,585 ✔
109
    if (verbosity) message_publish(MSG_DEBUG, "LOAD STATE: ");
39,247,585 ✔
110
    while (next_arg != (double*) NULL) {
196,357,649 ✔
111
        if (i >= num_state)
157,110,064 ✔
112
        {
NEW
113
            message_publish(MSG_ERROR, "Integrator::state_in: too many states (capacity %d).\n", num_state);
×
NEW
114
            return;
×
115
        }
116
        state[i] = *next_arg;
157,110,064 ✔
117
        if (verbosity) message_publish(MSG_DEBUG, "  %g", *next_arg);
157,110,064 ✔
118
        next_arg = va_arg(argp, double*);
157,110,064 ✔
119
        i++;
157,110,064 ✔
120
    }
121
    if (verbosity) message_publish(MSG_DEBUG, "\n");
39,247,585 ✔
122
}
123
#else
124
void Trick::Integrator::state_in (double* arg1, va_list argp) {
125
    if (intermediate_step == 0) {
126
        int i = 0;
127
        double* next_arg = arg1;
128
        if (verbosity) std::cout << "LOAD STATE: \n";
129
        while (next_arg != (double*) NULL) {
130
            if (i >= num_state)
131
            {
132
                message_publish(MSG_ERROR, "Integrator::state_in: too many states (capacity %d).\n", num_state);
133
                return;
134
            }
135
            state_origin[i] = next_arg;
136
            state[i] = *next_arg;
137
            if (verbosity) std::cout << "  " << *next_arg << "\n";
138
            next_arg = va_arg(argp, double*);
139
            i++;
140
        }
141
        if (verbosity) std::cout << std::endl;
142
    }
143
}
144

145
void Trick::Integrator::state_element_in (unsigned int index , double* state_p) {
146
    if (intermediate_step == 0) {
147
        state_origin[index] = state_p;
148
        state[index] = *state_p;
149
    }
150
}
151

152
#endif
153

154
void Trick::Integrator::state_in (double* arg1, ...) {
29,139 ✔
155
    va_list argp;
156
    va_start(argp, arg1);
29,139 ✔
157
    state_in(arg1, argp);
29,139 ✔
158
    va_end(argp);
29,139 ✔
159
}
29,139 ✔
160

161
void Trick::Integrator::deriv_in ( double* arg1, va_list argp) {
39,247,585 ✔
162
    int i = 0;
39,247,585 ✔
163
    double* next_arg = arg1;
39,247,585 ✔
164
    if (verbosity) message_publish(MSG_DEBUG, "LOAD DERIV: ");
39,247,585 ✔
165
    while (next_arg != (double*) NULL) {
196,357,649 ✔
166
        deriv[intermediate_step][i] = *next_arg;
157,110,064 ✔
167
        if (verbosity) message_publish(MSG_DEBUG,"  %g", *next_arg);
157,110,064 ✔
168
        next_arg = va_arg(argp, double*);
157,110,064 ✔
169
        i++;
157,110,064 ✔
170
    }
171
    if (verbosity) message_publish(MSG_DEBUG,"\n");
39,247,585 ✔
172
}
39,247,585 ✔
173

174
void Trick::Integrator::deriv_in ( double* arg1, ...) {
29,139 ✔
175
    va_list argp;
176
    va_start(argp, arg1);
29,139 ✔
177
    deriv_in(arg1, argp);
29,139 ✔
178
    va_end(argp);
29,139 ✔
179
}
29,139 ✔
180

181
void Trick::Integrator::deriv2_in ( double* arg1, va_list argp) {
1,402 ✔
182
    int i = 0;
1,402 ✔
183
    double* next_arg = arg1;
1,402 ✔
184
    if (verbosity) message_publish(MSG_DEBUG, "LOAD DERIV2: ");
1,402 ✔
185
    while (next_arg != (double*) NULL) {
4,206 ✔
186
        deriv2[intermediate_step][i] = *next_arg;
2,804 ✔
187
        if (verbosity) message_publish(MSG_DEBUG,"  %g", *next_arg);
2,804 ✔
188
        next_arg = va_arg(argp, double*);
2,804 ✔
189
        i++;
2,804 ✔
190
    }
191
    if (verbosity) message_publish(MSG_DEBUG,"\n");
1,402 ✔
192
}
1,402 ✔
193

194
void Trick::Integrator::deriv2_in ( double* arg1, ...) {
882 ✔
195
    va_list argp;
196
    va_start(argp, arg1);
882 ✔
197
    deriv2_in(arg1, argp);
882 ✔
198
    va_end(argp);
882 ✔
199
}
882 ✔
200

201
void Trick::Integrator::state_out (double* arg1, va_list argp) {
39,247,585 ✔
202
    int i = 0;
39,247,585 ✔
203
    double* next_arg = arg1;
39,247,585 ✔
204
    if (verbosity) message_publish(MSG_DEBUG, "UNLOAD STATE: ");
39,247,585 ✔
205
    while (next_arg != (double*) NULL) {
196,360,453 ✔
206
        *next_arg = state_ws[intermediate_step][i];
157,112,868 ✔
207
        if (verbosity) message_publish(MSG_DEBUG,"  %g", *next_arg);
157,112,868 ✔
208
        next_arg = va_arg(argp, double*);
157,112,868 ✔
209
        i++;
157,112,868 ✔
210
    }
211
    if (verbosity) message_publish(MSG_DEBUG,"\n");
39,247,585 ✔
212
}
39,247,585 ✔
213

214
void Trick::Integrator::state_out (double* arg1, ...) {
29,139 ✔
215
    va_list argp;
216
    va_start(argp, arg1);
29,139 ✔
217
    state_out(arg1, argp);
29,139 ✔
218
    va_end(argp);
29,139 ✔
219
}
29,139 ✔
220

221
bool Trick::Integrator::get_first_step_deriv() {
8 ✔
222
    return (first_step_deriv);
8 ✔
223
}
224

225
void Trick::Integrator::set_first_step_deriv(bool first_step) {
8 ✔
226
    first_step_deriv = first_step;
8 ✔
227
}
8 ✔
228

229
bool Trick::Integrator::get_last_step_deriv() {
8 ✔
230
    return (last_step_deriv);
8 ✔
231
}
232

233
void Trick::Integrator::set_last_step_deriv(bool last_step) {
8 ✔
234
    last_step_deriv = last_step;
8 ✔
235
}
8 ✔
236

237
void Trick::Integrator::set_verbosity(int level) {
×
238
    verbosity = level;
×
239
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc