Skip to content

Commit d8e613b

Browse files
Thierry Fourniervladbukin
authored andcommitted
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"
1 parent cd3b500 commit d8e613b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/actions/transformations/hex_encode.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ std::string HexEncode::evaluate(std::string value,
4141

4242
std::stringstream result;
4343
for (std::size_t i=0; i < value.length(); i++) {
44-
int ii = reinterpret_cast<char>(value[i]);
44+
unsigned int ii = (unsigned char)(value[i]);
4545
result << std::setw(2) << std::setfill('0') << std::hex << ii;
4646
}
4747

0 commit comments

Comments
 (0)