Skip to content

Commit

Permalink
fix hexInt sprintf format pattern (#5460)
Browse files Browse the repository at this point in the history
close #5462
  • Loading branch information
YangKeao authored Jul 26, 2022
1 parent a476307 commit c4ad3f1
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions dbms/src/Functions/FunctionsString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5281,18 +5281,17 @@ class FunctionHexInt : public IFunction
ColumnString::Offsets & res_offsets = col_res->getOffsets();
res_offsets.resize(size);

size_t prev_res_offset = 0;
auto res_chars_iter = res_chars.begin();
for (size_t i = 0; i < size; ++i)
{
UInt64 number = col->getUInt(i);

int print_size = sprintf(reinterpret_cast<char *>(&res_chars[prev_res_offset]), "%lX", number);
res_chars[prev_res_offset + print_size] = 0;
res_chars_iter = fmt::format_to(res_chars_iter, "{:X}", number);
*(++res_chars_iter) = 0;
// Add the size of printed string and a tailing zero
prev_res_offset += print_size + 1;
res_offsets[i] = prev_res_offset;
res_offsets[i] = res_chars_iter - res_chars.begin();
}
res_chars.resize(prev_res_offset);
res_chars.resize(res_chars_iter - res_chars.begin());

block.getByPosition(result).column = std::move(col_res);

Expand Down

0 comments on commit c4ad3f1

Please sign in to comment.