Selaa lähdekoodia

Fix compilation error where gcc 12.1.0 (MinGW) errors with "writing 1 byte into a region of size 0"

Joakim Thorén 1 vuosi sitten
vanhempi
sitoutus
100664e019
1 muutettua tiedostoa jossa 4 lisäystä ja 5 poistoa
  1. 4 5
      client/render/Colors.cpp

+ 4 - 5
client/render/Colors.cpp

@@ -29,11 +29,11 @@ std::optional<ColorRGBA> Colors::parseColor(std::string text)
 {
 	std::smatch match;
 	std::regex expr("^#([0-9a-fA-F]{6})$");
-	ui8 rgb[3] = {0, 0, 0};
+	std::vector<ui8> rgb;
+	rgb.reserve(3);
 	if(std::regex_search(text, match, expr))
 	{
-		std::string tmp = boost::algorithm::unhex(match[1].str()); 
-		std::copy(tmp.begin(), tmp.end(), rgb);
+		boost::algorithm::unhex(match[1].str(), std::back_inserter(rgb)); 
 		return ColorRGBA(rgb[0], rgb[1], rgb[2]);
 	}
 
@@ -42,8 +42,7 @@ std::optional<ColorRGBA> Colors::parseColor(std::string text)
 	for(auto & color : colors) {
 		if(boost::algorithm::to_lower_copy(color.first) == boost::algorithm::to_lower_copy(text))
 		{
-			std::string tmp = boost::algorithm::unhex(color.second.String()); 
-			std::copy(tmp.begin(), tmp.end(), rgb);
+			boost::algorithm::unhex(color.second.String(), std::back_inserter(rgb)); 
 			return ColorRGBA(rgb[0], rgb[1], rgb[2]);
 		}
 	}