Skip to content

Commit

Permalink
format_number_with_delim: simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPulec committed Jan 21, 2025
1 parent 2e8ca3e commit ef9f421
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/gpujpeg_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2180,19 +2180,12 @@ format_number_with_delim(size_t num, char* buf, size_t buflen)
const int tmp = num % 1000;
num /= 1000;
if ( num == 0 ) {
ptr -= 1;
if ( tmp >= 10 ) {
ptr -= 1;
if ( tmp >= 100 ) {
ptr -= 1;
}
}
char numbuf[4];
ptr -= snprintf(numbuf, sizeof numbuf, "%i", tmp);
if ( ptr < buf ) {
snprintf(buf, buflen, "%s", "ERR");
return buf;
}
char numbuf[4];
snprintf(numbuf, sizeof numbuf, "%i", tmp);
// NOLINTNEXTLINE(bugprone-not-null-terminated-result): prepending, no null-termination
memcpy(ptr, numbuf, strlen(numbuf));
return ptr;
Expand Down

0 comments on commit ef9f421

Please sign in to comment.