Closed schwehr closed 3 years ago
Kurt, please make a PR. I need the practice.
When I add the checks, it breaks this test with ut_encode_clock
called with -1 0 -0.000000
unit = ut_parse(unitSystem,
"second since 1970-01-01 0 -1", UT_ASCII);
CU_ASSERT_PTR_NOT_NULL(unit);
if (unit) {
converter = ut_get_converter(unit, secondsSinceTheEpoch);
CU_ASSERT_PTR_NOT_NULL(converter);
if (converter) {
CU_ASSERT_TRUE(areCloseDoubles(cv_convert_double(converter, 0), 3600));
cv_free(converter);
}
ut_free(unit);
}
udunits2
You have: second since 1970-01-01 0 -1
You want: second since 1970-01-01 0 0
1 second since 1970-01-01 0 -1 = 3601 (second since 1970-01-01 0 0)
x/(second since 1970-01-01 0 0) = (x/(second since 1970-01-01 0 -1)) + 3600
So what should ut_encode_clock be doing? Should hour be > -24? min > -60 and sec >= -62?
This was fixed in https://github.com/Unidata/UDUNITS-2/commit/5d956f7624fff8080679b9f80fe80d7ae043f8c8 with the abs and fabs:
if (abs(hours) >= 24 || abs(minutes) >= 60 || fabs(seconds) > 62) {
ut_set_status(UT_BAD_ARG);
return 0;
}
To report a non-security related issue, please provide:
8fb0b21826a9abcd36e097bd1cb8c95c947b9526
linux custom
testcase-5704996435787776.zip
The fix:
I can make a pr if the fix is acceptable.