From 3031b7cf6ac171417f4eb78d517ece3be48f5804 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Mon, 19 Apr 2021 08:54:34 +0100 Subject: [PATCH] SVG parse_svg_value/parse_font_size: re-initialise default val on parser failure --- src/svg/svg_parser.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/svg/svg_parser.cpp b/src/svg/svg_parser.cpp index 8bae77323..9b5af151b 100644 --- a/src/svg/svg_parser.cpp +++ b/src/svg/svg_parser.cpp @@ -268,15 +268,16 @@ double parse_svg_value(T & parser, char const* str, bool & is_percent) x3::space) || (cur != end)) { parser.err_handler().on_error("SVG parse error: failed to parse with value \"" + std::string(str) + "\""); + val = 0.0; // re-initialise to default value } return val; } template -double parse_font_size(T & parser, char const* str) +bool parse_font_size(T & parser, char const* str) { namespace x3 = boost::spirit::x3; - double val; + double val = 0.0; css_unit_value units; css_absolute_size absolute; css_relative_size relative; @@ -292,20 +293,21 @@ double parse_font_size(T & parser, char const* str) auto apply_percent = [&](auto const& ctx) { val = val * parent_font_size / 100.0;}; auto apply_em = [&](auto const& ctx) { val = val * parent_font_size;}; if (!x3::phrase_parse(cur, end, - absolute[apply_value] - | - relative[apply_relative] - | - x3::double_[apply_value] - > -(units[apply_units] - | x3::lit("em")[apply_em] - | x3::lit('%')[apply_percent]), - x3::space) || (cur != end)) + absolute[apply_value] + | + relative[apply_relative] + | + x3::double_[apply_value] + > -(units[apply_units] + | x3::lit("em")[apply_em] + | x3::lit('%')[apply_percent]), + x3::space) || (cur != end)) { parser.err_handler().on_error("SVG parse error: failed to parse with value \"" + std::string(str) + "\""); + return false; } if (!parser.font_sizes_.empty()) parser.font_sizes_.back() = val; - return val; + return true; } template