From a0a4c926c14f19a4aa28abf2fa98f94da16e4641 Mon Sep 17 00:00:00 2001 From: "Simon Schmeisser (isys vision)" Date: Mon, 29 Oct 2018 12:11:58 +0100 Subject: [PATCH] Add range check for color components being within [0, 1] 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 --- urdf_model/include/urdf_model/color.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/urdf_model/include/urdf_model/color.h b/urdf_model/include/urdf_model/color.h index 46915a5..fec8ae0 100644 --- a/urdf_model/include/urdf_model/color.h +++ b/urdf_model/include/urdf_model/color.h @@ -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)");