From 051134a21e16d16804838aa5d020d94248a8431d Mon Sep 17 00:00:00 2001 From: davidot Date: Wed, 12 Oct 2022 12:37:09 +0200 Subject: [PATCH] LibGfx: Make parse_rgba_color use the new double parser Since this is used by LibWeb when parsing CSS colors we should not use strtod here. --- Userland/Libraries/LibGfx/Color.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGfx/Color.cpp b/Userland/Libraries/LibGfx/Color.cpp index 134e9fa71f..45e2b98d6f 100644 --- a/Userland/Libraries/LibGfx/Color.cpp +++ b/Userland/Libraries/LibGfx/Color.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -63,7 +64,12 @@ static Optional parse_rgba_color(StringView string) auto g = parts[1].to_int().value_or(256); auto b = parts[2].to_int().value_or(256); - double alpha = strtod(parts[3].to_string().characters(), nullptr); + double alpha = 0; + char const* start = parts[3].characters_without_null_termination(); + auto alpha_result = parse_first_floating_point(start, start + parts[3].length()); + if (alpha_result.parsed_value()) + alpha = alpha_result.value; + unsigned a = alpha * 255; if (r > 255 || g > 255 || b > 255 || a > 255)