Skip to content

Commit

Permalink
microtez_to_string: clarify the trailing 0s elimination
Browse files Browse the repository at this point in the history
Using while and index
  • Loading branch information
spalmer25 committed Apr 22, 2024
1 parent 9f00c8d commit ee64404
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/to_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,11 @@ int microtez_to_string(char *const dest, size_t dest_size, uint64_t number) {

// Eliminate trailing 0s
char *start = tmp + sizeof(tmp) - DECIMAL_DIGITS;
char *end;
for (end = tmp + sizeof(tmp) - 1u; end >= start; end--) {
if (*end != '0') {
end++;
break;
}
size_t length = DECIMAL_DIGITS;
while ((length > 0) && (start[length - 1u] == '0')) {
length--;
}

size_t length = end - start;
if ((dest_size - offset) < length) {
return -1;
}
Expand Down

0 comments on commit ee64404

Please sign in to comment.