py: Fix pfenv_print_strn to return correct number of chars printed.
With this fix, all tests in tests/basics pass on pyboard.
This commit is contained in:
parent
71d3112f7e
commit
d0f9f6cd3f
10
py/pfenv.c
10
py/pfenv.c
@ -29,6 +29,7 @@ int pfenv_print_strn(const pfenv_t *pfenv, const char *str, unsigned int len, in
|
||||
int right_pad = 0;
|
||||
int pad = width - len;
|
||||
int pad_size;
|
||||
int total_chars_printed = 0;
|
||||
const char *pad_chars;
|
||||
|
||||
if (!fill || fill == ' ' ) {
|
||||
@ -53,7 +54,8 @@ int pfenv_print_strn(const pfenv_t *pfenv, const char *str, unsigned int len, in
|
||||
left_pad = pad;
|
||||
}
|
||||
|
||||
if (left_pad) {
|
||||
if (left_pad > 0) {
|
||||
total_chars_printed += left_pad;
|
||||
while (left_pad > 0) {
|
||||
int p = left_pad;
|
||||
if (p > pad_size) {
|
||||
@ -64,7 +66,9 @@ int pfenv_print_strn(const pfenv_t *pfenv, const char *str, unsigned int len, in
|
||||
}
|
||||
}
|
||||
pfenv->print_strn(pfenv->data, str, len);
|
||||
if (right_pad) {
|
||||
total_chars_printed += len;
|
||||
if (right_pad > 0) {
|
||||
total_chars_printed += right_pad;
|
||||
while (right_pad > 0) {
|
||||
int p = right_pad;
|
||||
if (p > pad_size) {
|
||||
@ -74,7 +78,7 @@ int pfenv_print_strn(const pfenv_t *pfenv, const char *str, unsigned int len, in
|
||||
right_pad -= p;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
return total_chars_printed;
|
||||
}
|
||||
|
||||
// 32-bits is 10 digits, add 3 for commas, 1 for sign, 1 for terminating null
|
||||
|
@ -244,7 +244,7 @@ void strn_print_strn(void *data, const char *str, unsigned int len) {
|
||||
strn_pfenv->cur += len;
|
||||
strn_pfenv->remain -= len;
|
||||
}
|
||||
|
||||
|
||||
int vsnprintf(char *str, size_t size, const char *fmt, va_list ap) {
|
||||
strn_pfenv_t strn_pfenv;
|
||||
strn_pfenv.cur = str;
|
||||
|
Loading…
Reference in New Issue
Block a user