summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--py/pfenv.c10
-rw-r--r--stmhal/printf.c2
2 files changed, 8 insertions, 4 deletions
diff --git a/py/pfenv.c b/py/pfenv.c
index 310ca07aa4..92c4018415 100644
--- a/py/pfenv.c
+++ b/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
diff --git a/stmhal/printf.c b/stmhal/printf.c
index b1eace28de..ea90f49803 100644
--- a/stmhal/printf.c
+++ b/stmhal/printf.c
@@ -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;