From bf83eb37582dba081aa0ca8bc5c461ea4066527b Mon Sep 17 00:00:00 2001 From: Thierry Fournier Date: Wed, 10 Apr 2019 23:42:08 +0200 Subject: [PATCH] fix/minor: Error encoding hexa decimal String is defined as an array of char. The char can be negative. The cast "reinterpret_cast" from char to int keep the negative side, so the "unsigned char" number 0x91 is negative as "char". When it is "reinterpret_cast" as integer, it becomes 0xffffff91, so the hexadecimal display is broken: [155493246391.747672] [/absolute?what=badarg2] [9] T (0) t:hexEncode: "ffffff91ffffffecffffffe6334bffffffebffffff87ffffff9affffff824a06ffffffc33b4cffff (14 characters omitted)" This patch fix this behavior using classic cast without reinterpret_cast: [155493251286.221115] [/absolute?what=badarg2] [9] T (0) t:hexEncode: "91ece6334beb879a824a06c33b4cb4240e4c6f56" --- src/actions/transformations/hex_encode.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/transformations/hex_encode.cc b/src/actions/transformations/hex_encode.cc index 51f3099548..4f55d1fe10 100644 --- a/src/actions/transformations/hex_encode.cc +++ b/src/actions/transformations/hex_encode.cc @@ -41,7 +41,7 @@ std::string HexEncode::evaluate(std::string value, std::stringstream result; for (std::size_t i=0; i < value.length(); i++) { - int ii = reinterpret_cast(value[i]); + unsigned int ii = (unsigned char)(value[i]); result << std::setw(2) << std::setfill('0') << std::hex << ii; }