]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Css: Use old good strtod that does not throw exceptions
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 6 May 2021 10:31:57 +0000 (11:31 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 6 May 2021 10:31:57 +0000 (11:31 +0100)
src/libserver/css/css_tokeniser.cxx

index 0374193bf766794fa65df8184c9b97df67a4f817..f4180b761b4491ad9e8a47cea92062f8ec2baf48 100644 (file)
@@ -364,8 +364,13 @@ auto css_tokeniser::consume_number() -> struct css_parser_token
 
                /* I wish it was supported properly */
                //auto conv_res = std::from_chars(&input[offset], &input[i], num);
-               std::string numbuf{&input[offset], (i - offset)};
-               num = std::stod(numbuf);
+               char numbuf[128], *endptr = NULL;
+               rspamd_strlcpy(numbuf, &input[offset], MIN(i - offset + 1, sizeof(numbuf)));
+               num = g_ascii_strtod(numbuf, &endptr);
+
+               if (endptr && *endptr != '\0') {
+                       msg_debug_css("invalid number: %s", numbuf);
+               }
                offset = i;
 
                auto ret = make_token<css_parser_token::token_type::number_token>(num);