Skip to content

Commit 708fff7

Browse files
Fixed undefined behavior with log10 cast of fractional doubles (#276)
1 parent 2f35c28 commit 708fff7

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

include/toml++/impl/toml_formatter.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ TOML_ANON_NAMESPACE_START
9191
weight += 1u;
9292
val *= -1.0;
9393
}
94-
return weight + static_cast<size_t>(log10(val)) + 1u;
94+
return weight + static_cast<size_t>(abs(log10(val))) + 1u;
9595
}
9696

9797
case node_type::boolean: return 5u;

toml.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17107,7 +17107,7 @@ TOML_ANON_NAMESPACE_START
1710717107
weight += 1u;
1710817108
val *= -1.0;
1710917109
}
17110-
return weight + static_cast<size_t>(log10(val)) + 1u;
17110+
return weight + static_cast<size_t>(abs(log10(val))) + 1u;
1711117111
}
1711217112

1711317113
case node_type::boolean: return 5u;

0 commit comments

Comments
 (0)