From cc7d18d29a5314c6350b7378bc788f48f3925337 Mon Sep 17 00:00:00 2001 From: Karol Gugala Date: Wed, 27 Jan 2021 20:34:00 +0100 Subject: [PATCH] frontend: json: parse negative values Signed-off-by: Karol Gugala --- frontends/json/jsonparse.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/frontends/json/jsonparse.cc b/frontends/json/jsonparse.cc index 1b34aaf3a..312f6d3be 100644 --- a/frontends/json/jsonparse.cc +++ b/frontends/json/jsonparse.cc @@ -72,10 +72,17 @@ struct JsonNode break; } - if ('0' <= ch && ch <= '9') + if (('0' <= ch && ch <= '9') || ch == '-') { + bool negative = false; type = 'N'; - data_number = ch - '0'; + if (ch == '-') { + data_number = 0; + negative = true; + } else { + data_number = ch - '0'; + } + data_string += ch; while (1) @@ -97,6 +104,7 @@ struct JsonNode data_string += ch; } + data_number = negative ? -data_number : data_number; data_string = ""; break; -- 2.30.2