@@ -90,9 +90,13 @@ static void environment_init_modes(environment_t* env, int num_modes, int num_st
9090 modes -> modal_reactor_states_size = num_modes ;
9191 modes -> triggered_reactions_request = 0 ;
9292
93- modes -> state_resets = (mode_state_variable_reset_data_t * ) calloc (num_state_resets , sizeof (mode_state_variable_reset_data_t ));
94- LF_ASSERT (modes -> state_resets , "Out of memory" );
9593 modes -> state_resets_size = num_state_resets ;
94+ if (modes -> state_resets_size > 0 ) {
95+ modes -> state_resets = (mode_state_variable_reset_data_t * ) calloc (modes -> state_resets_size , sizeof (mode_state_variable_reset_data_t ));
96+ LF_ASSERT (modes -> state_resets , "Out of memory" );
97+ } else {
98+ modes -> state_resets = NULL ;
99+ }
96100
97101 env -> modes = modes ;
98102
@@ -107,9 +111,13 @@ static void environment_init_modes(environment_t* env, int num_modes, int num_st
107111 */
108112static void environment_init_federated (environment_t * env , int num_is_present_fields ) {
109113#ifdef FEDERATED_DECENTRALIZED
110- env -> _lf_intended_tag_fields = (tag_t * * ) calloc (num_is_present_fields , sizeof (tag_t * ));
111- LF_ASSERT (env -> _lf_intended_tag_fields , "Out of memory" );
112- env -> _lf_intended_tag_fields_size = num_is_present_fields ;
114+ if (num_is_present_fields > 0 ) {
115+ env -> _lf_intended_tag_fields = (tag_t * * ) calloc (num_is_present_fields , sizeof (tag_t * ));
116+ LF_ASSERT (env -> _lf_intended_tag_fields , "Out of memory" );
117+ env -> _lf_intended_tag_fields_size = num_is_present_fields ;
118+ } else {
119+ env -> _lf_intended_tag_fields_size = NULL ;
120+ }
113121#endif
114122}
115123
@@ -197,29 +205,49 @@ int environment_init(
197205 env -> stop_tag = FOREVER_TAG ;
198206
199207 env -> timer_triggers_size = num_timers ;
200- env -> timer_triggers = (trigger_t * * ) calloc (num_timers , sizeof (trigger_t ));
201- LF_ASSERT (env -> timer_triggers , "Out of memory" );
208+ if (env -> timer_triggers_size > 0 ) {
209+ env -> timer_triggers = (trigger_t * * ) calloc (num_timers , sizeof (trigger_t ));
210+ LF_ASSERT (env -> timer_triggers , "Out of memory" );
211+ } else {
212+ env -> timer_triggers = NULL ;
213+ }
202214
203215 env -> startup_reactions_size = num_startup_reactions ;
204- env -> startup_reactions = (reaction_t * * ) calloc (num_startup_reactions , sizeof (reaction_t ));
205- LF_ASSERT (env -> startup_reactions , "Out of memory" );
216+ if (env -> startup_reactions_size > 0 ) {
217+ env -> startup_reactions = (reaction_t * * ) calloc (num_startup_reactions , sizeof (reaction_t ));
218+ LF_ASSERT (env -> startup_reactions , "Out of memory" );
219+ } else {
220+ env -> startup_reactions = NULL ;
221+ }
206222
207223 env -> shutdown_reactions_size = num_shutdown_reactions ;
208- env -> shutdown_reactions = (reaction_t * * ) calloc (num_shutdown_reactions , sizeof (reaction_t ));
209- LF_ASSERT (env -> shutdown_reactions , "Out of memory" );
224+ if (env -> shutdown_reactions_size > 0 ) {
225+ env -> shutdown_reactions = (reaction_t * * ) calloc (num_shutdown_reactions , sizeof (reaction_t ));
226+ LF_ASSERT (env -> shutdown_reactions , "Out of memory" );
227+ } else {
228+ env -> shutdown_reactions = NULL ;
229+ }
210230
211231 env -> reset_reactions_size = num_reset_reactions ;
212- env -> reset_reactions = (reaction_t * * ) calloc (num_reset_reactions , sizeof (reaction_t ));
213- LF_ASSERT (env -> reset_reactions , "Out of memory" );
232+ if (env -> reset_reactions_size > 0 ) {
233+ env -> reset_reactions = (reaction_t * * ) calloc (num_reset_reactions , sizeof (reaction_t ));
234+ LF_ASSERT (env -> reset_reactions , "Out of memory" );
235+ } else {
236+ env -> reset_reactions = NULL ;
237+ }
214238
215239 env -> is_present_fields_size = num_is_present_fields ;
216240 env -> is_present_fields_abbreviated_size = 0 ;
217241
218- env -> is_present_fields = (bool * * )calloc (num_is_present_fields , sizeof (bool * ));
219- LF_ASSERT (env -> is_present_fields , "Out of memory" );
220-
221- env -> is_present_fields_abbreviated = (bool * * )calloc (num_is_present_fields , sizeof (bool * ));
222- LF_ASSERT (env -> is_present_fields_abbreviated , "Out of memory" );
242+ if (env -> is_present_fields_size > 0 ) {
243+ env -> is_present_fields = (bool * * )calloc (num_is_present_fields , sizeof (bool * ));
244+ LF_ASSERT (env -> is_present_fields , "Out of memory" );
245+ env -> is_present_fields_abbreviated = (bool * * )calloc (num_is_present_fields , sizeof (bool * ));
246+ LF_ASSERT (env -> is_present_fields_abbreviated , "Out of memory" );
247+ } else {
248+ env -> is_present_fields = NULL ;
249+ env -> is_present_fields_abbreviated = NULL ;
250+ }
223251
224252 env -> _lf_handle = 1 ;
225253
0 commit comments