Opened 19 months ago

Last modified 19 months ago

#5609 assigned defect

Unnecessary assert in 2.0 variable parsing

Reported by: hlarsson Owned by: hlarsson
Priority: major Milestone:
Component: FMILibrary Version: trunk
Keywords: Cc:


fmi2_xml_get_has_start in src/XML/src/FMI2/fmi2_xml_variable.c contains
an assert() against an error that is already handled

if(!hasStart)  {
       Variables with causality = "parameter" or "input", as well as variables with variability = "constant", must have a "start" value.
       If initial = exact or approx, a start value must be provided.
       The second condition is actually enough since parameters and inputs and constants must be "initial=exact"
    if(    (variable->causality == (char)fmi2_causality_enu_parameter)
        || (variable->causality == (char)fmi2_causality_enu_input)
        || (variable->variability == (char)fmi2_variability_enu_constant)) {

            assert(variable->initial != (char)fmi2_initial_enu_exact);

    if (variable->initial != (char)fmi2_initial_enu_calculated)
        fmi2_xml_parse_error(context, "Start attribute is required for this causality, variability and initial combination");
        hasStart = 1;

As the comment in the code notes, the second if-statement should be enough. The only effect of the assertion is then to break execution in debug builds, even though the error would be detected anyway.

Change History (3)

comment:1 Changed 19 months ago by hlarsson

r10945: Removing assert for invalid initial, since the error is found by the parser and logged correctly anyway.

Last edited 19 months ago by hlarsson (previous) (diff)

comment:2 Changed 19 months ago by hlarsson

r10947: Improving comment about check of initial kind.

comment:3 Changed 19 months ago by hlarsson

r10948: Removing comment altogether.

Note: See TracTickets for help on using tickets.