Skip to content

Commit 0d641bc

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 075da98 + 29d136d commit 0d641bc

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Primarily designed for usage in embedded systems, where printf is not available
1212
Using the standard libc printf may pull **a lot** of unwanted library stuff and can bloat code size about 20k or is not 100% thread safe. In this cases the following implementation can be used.
1313
Absolutely **NO dependencies** are required, *printf.c* brings all necessary routines, even its own fast `ftoa` (floating point), `ntoa` (decimal) conversion.
1414

15-
If memory footprint is really a critical issue, floating point and 'long long' support and can be turned off via the `PRINTF_SUPPORT_FLOAT` and `PRINTF_SUPPORT_LONG_LONG` compiler switches.
15+
If memory footprint is really a critical issue, floating point and 'long long' support and can be turned off via the `PRINTF_DISABLE_SUPPORT_FLOAT` and `PRINTF_DISABLE_SUPPORT_LONG_LONG` compiler switches.
1616
When using printf (instead of sprintf/snprintf) you have to provide your own `_putchar()` low level function as console/serial output.
1717

1818

printf.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,13 @@ static size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, size_t ma
174174
const size_t start_idx = idx;
175175

176176
// pad leading zeros
177-
while (!(flags & FLAGS_LEFT) && (len < prec) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
178-
buf[len++] = '0';
179-
}
180-
while (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
181-
buf[len++] = '0';
177+
if (!(flags & FLAGS_LEFT)) {
178+
while ((len < prec) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
179+
buf[len++] = '0';
180+
}
181+
while ((flags & FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
182+
buf[len++] = '0';
183+
}
182184
}
183185

184186
// handle hash
@@ -389,8 +391,10 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
389391
}
390392

391393
// pad leading zeros
392-
while (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_FTOA_BUFFER_SIZE)) {
393-
buf[len++] = '0';
394+
if (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD)) {
395+
while ((len < width) && (len < PRINTF_FTOA_BUFFER_SIZE)) {
396+
buf[len++] = '0';
397+
}
394398
}
395399

396400
// handle sign

0 commit comments

Comments
 (0)