@@ -35,6 +35,7 @@ absl::optional<int64_t> HexColorToInt(absl::string_view value) {
3535 if (color_string.size () != 6 ) {
3636 return absl::nullopt ;
3737 }
38+ errno = 0 ;
3839 uint64_t v = std::strtoul ( // NOLINT(runtime/deprecated_fn)
3940 color_string.c_str (), nullptr , 16 );
4041 if (errno == ERANGE) {
@@ -67,25 +68,25 @@ uint32_t GetMatchColor(double value) {
6768 }();
6869
6970 static auto * color_ramp = []() -> std::vector<uint32_t >* {
70- auto * color_ramp = new std::vector< uint32_t >(
71- ParseColorRamp (default_theme .similarity_ramp ()));
71+ auto * color_ramp =
72+ new std::vector< uint32_t >( ParseColorRamp (theme .similarity_ramp ()));
7273 if (color_ramp->empty () ||
7374 color_ramp->size () != theme.similarity_ramp_size ()) {
74- // Parse error, set default color ramp
75+ // Parse error, set default color ramp. This should never fail, as the
76+ // data is embedded.
7577 *color_ramp = ParseColorRamp (default_theme.similarity_ramp ());
7678 }
7779 return color_ramp;
7880 }();
7981
8082 static uint32_t manual_match_color = *HexColorToInt (theme.manual_match ());
8183
82- uint32_t color;
84+ uint32_t color = 0xffffff ; // Fallback to white
8385 if (value == kManualMatch ) {
8486 color = manual_match_color;
85- } else if (value >= 0.0 && value <= 1.0 ) {
86- color = (*color_ramp)[static_cast <int >(value * (color_ramp->size () - 1 ))];
87- } else {
88- color = 0xffffff ; // Fallback to white
87+ } else if (size_t ramp_size = color_ramp->size ();
88+ ramp_size > 0 && value >= 0.0 && value <= 1.0 ) {
89+ color = (*color_ramp)[static_cast <int >(value * (ramp_size - 1 ))];
8990 }
9091 return (color << 16 ) | (color & 0xff00 ) | (color >> 16 );
9192}
0 commit comments