Skip to content

Commit

Permalink
Add remaining errno checks
Browse files Browse the repository at this point in the history
  • Loading branch information
j9liu committed Jan 10, 2024
1 parent fbad0f5 commit f6a71d8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions CesiumGltf/include/CesiumGltf/MetadataConversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,12 @@ template <> struct MetadataConversions<float, std::string> {
return std::nullopt;
}

errno = 0;

char* pLastUsed;
float parsedValue = std::strtof(from.c_str(), &pLastUsed);
if (pLastUsed == from.c_str() + from.size() && !std::isinf(parsedValue)) {
if (errno == 0 && pLastUsed == from.c_str() + from.size() &&
!std::isinf(parsedValue)) {
// Successfully parsed the entire string as a float.
return parsedValue;
}
Expand Down Expand Up @@ -519,9 +522,12 @@ template <> struct MetadataConversions<double, std::string> {
return std::nullopt;
}

errno = 0;

char* pLastUsed;
double parsedValue = std::strtod(from.c_str(), &pLastUsed);
if (pLastUsed == from.c_str() + from.size() && !std::isinf(parsedValue)) {
if (errno == 0 && pLastUsed == from.c_str() + from.size() &&
!std::isinf(parsedValue)) {
// Successfully parsed the entire string as a double.
return parsedValue;
}
Expand Down

0 comments on commit f6a71d8

Please sign in to comment.