From 88fbe3ac3436961ffe26842080024cbf8ce64dc4 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Thu, 15 Apr 2021 11:21:34 +0200 Subject: [PATCH] Fixed undefined behavior in JSON serializer --- src/ArduinoJson/Json/TextFormatter.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ArduinoJson/Json/TextFormatter.hpp b/src/ArduinoJson/Json/TextFormatter.hpp index 23d16d03..18694f14 100644 --- a/src/ArduinoJson/Json/TextFormatter.hpp +++ b/src/ArduinoJson/Json/TextFormatter.hpp @@ -92,9 +92,9 @@ class TextFormatter { unsigned_type unsigned_value; if (value < 0) { writeRaw('-'); - unsigned_value = static_cast(-value); + unsigned_value = unsigned_type(unsigned_type(~value) + 1); } else { - unsigned_value = static_cast(value); + unsigned_value = unsigned_type(value); } writeInteger(unsigned_value); }