Skip to content

Commit

Permalink
Add range check for color components being within [0, 1]
Browse files Browse the repository at this point in the history
this solves the potential undefined behaviour in implicit conversion if a color component should
be greater than the maximum float but smaller than the maximum double and allows us
to reuse strToDouble safely
  • Loading branch information
simonschmeisser authored and scpeters committed Nov 14, 2018
1 parent f97cbce commit a0a4c92
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion urdf_model/include/urdf_model/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ class Color
{
try
{
rgba.push_back(strToDouble(pieces[i].c_str()));
double piece = strToDouble(pieces[i].c_str());
if ((piece < 0) || (piece > 1))
throw ParseError("Component [" + pieces[i] + "] is outside the valid range for colors [0, 1]");
rgba.push_back(piece);
}
catch (std::runtime_error &/*e*/) {
throw ParseError("Unable to parse component [" + pieces[i] + "] to a double (while parsing a color value)");
Expand Down

0 comments on commit a0a4c92

Please sign in to comment.