Skip to content

Commit

Permalink
[poincare/unit] Fix temperature conversion
Browse files Browse the repository at this point in the history
The program would crash when trying to evaluate a unit conversion of the
form "x→_U" where U was a unit of temperature and x did not have any
unit.
  • Loading branch information
GabrielNumworks authored and EmilieNumworks committed Dec 29, 2020
1 parent 5ce5f4f commit fff514d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion poincare/src/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ Expression Unit::ConvertTemperatureUnits(Expression e, Unit unit, ExpressionNode

Expression startUnit;
e = e.removeUnit(&startUnit);
if (startUnit.type() != ExpressionNode::Type::Unit) {
if (startUnit.isUninitialized() || startUnit.type() != ExpressionNode::Type::Unit) {
return Undefined::Builder();
}
const Representative * startRepr = static_cast<Unit &>(startUnit).representative();
Expand Down
1 change: 1 addition & 0 deletions poincare/test/simplification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,7 @@ QUIZ_CASE(poincare_simplification_unit_convert) {
assert_parsed_expression_simplify_to("1→3_m", Undefined::Name());
assert_parsed_expression_simplify_to("4→_km/_m", Undefined::Name());
assert_parsed_expression_simplify_to("3×_min→_s+1-1", Undefined::Name());
assert_parsed_expression_simplify_to("0→_K", Undefined::Name());

assert_parsed_expression_simplify_to("0_K→_°C", "-273.15×_°C");
assert_parsed_expression_simplify_to("0_°C→_K", "273.15×_K");
Expand Down

0 comments on commit fff514d

Please sign in to comment.