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 316208b
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 > 0u) && (start[length - 1u] == '0')) {

This comment has been minimized.

Copy link
@ajinkyaraj-23

ajinkyaraj-23 Apr 23, 2024

Collaborator

Can we add a test for testing a large microtez value to string? one with trailing zero , large fractional number etc.

length--;
}

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

0 comments on commit 316208b

Please sign in to comment.