Cantera / cantera

Chemical kinetics, thermodynamics, and transport tool suite
https://cantera.org
Other
582 stars 342 forks source link

Conversion from YAML input fails #1530

Closed ischoegl closed 11 months ago

ischoegl commented 1 year ago

Problem description

Converting a double -4.940656458412465e-324 within a YAML list crashes.

Steps to reproduce

  1. Add new google test to test_containers.cpp
TEST(AnyMap, loadYaml1)
{
    AnyMap m = AnyMap::fromYamlString(
        "scalar: -4.940656458412465e-324\n"
        "vector: [1.999999997714111, 1.482285197259138, 1.151630981915516,\n"
        "1.000344957481014, 0.9194396615839727, 0.9223835565362135,\n"
        "0.9891669199823520, 2.020682232759305, 2.972892634526984,\n"
        "3.610551734891259, 3.970292820568238, 3.893993665448339,\n"
        "2.957408463878464, 2.035192404627, -4.940656458412465e-324]\n");

    ASSERT_EQ(m["vector"].asVector<double>()[0], 2.);
}
  1. Run: scons test-general

  2. See error

[ RUN      ] AnyMap.loadYaml1
unknown file: Failure
C++ exception with description "
*******************************************************************************
InputFileError thrown by AnyMap::fromYamlString:
Error on line 6 of input string:
bad conversion
|  Line |
|     1 | scalar: -4.940656458412465e-324
|     2 | vector: [1.999999997714111, 1.482285197259138, 1.151630981915516,
|     3 | 1.000344957481014, 0.9194396615839727, 0.9223835565362135,
|     4 | 0.9891669199823520, 2.020682232759305, 2.972892634526984,
|     5 | 3.610551734891259, 3.970292820568238, 3.893993665448339,
>     6 > 2.957408463878464, 2.035192404627, -4.940656458412465e-324]
                                             ^
*******************************************************************************
" thrown in the test body.
[  FAILED  ] AnyMap.loadYaml1 (0 ms)

Behavior

The error presumably originates in AnyValue& operator[]. Loading a regular scalar works as expected.

For context: the offending YAML input was originally generated by Cantera's YAML serialization (specifically SolutionArray::writeEntry. The simplified test isolates the problematic behavior.

System information