chprintf enhancement Topic is solved

Use this forum for requesting small changes in ChibiOS. Large changes should be discussed in the development forum. This forum is NOT for support.
Post Reply
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

chprintf enhancement

Post by steved »

I made a small change to chprintf() to support '+' within the formatting definition.

Also wasn't clear on a quick look whether getting the width specification from a variable would work; I've highlighted this and suggested an alternative.
Attachments
chprintf.zip
(2.85 KiB) Downloaded 551 times
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chprintf enhancement

Post by Giovanni »

bump
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: chprintf enhancement

Post by steved »

Updated for 19.1
Attachments
chprintf.zip
(2.91 KiB) Downloaded 476 times
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chprintf enhancement

Post by Giovanni »

Hi,

I merged it with some fixes and also made some other changes. It is possible I introduced problems but it was needed, final zero was not always detected in the format string if malformed. That TODO was correct IMO, fixed that as well.

Giovanni
User avatar
FXCoder
Posts: 403
Joined: Sun Jun 12, 2016 4:10 am
Has thanked: 188 times
Been thanked: 134 times

Re: chprintf enhancement

Post by FXCoder »

Hi,
The .n precision was broken by the malformed format string detection...
--
Bob

Code: Select all

Index: chprintf.c
===================================================================
--- chprintf.c   (revision 12837)
+++ chprintf.c   (working copy)
@@ -203,18 +203,13 @@
         precision = va_arg(ap, int);
       }
       else {
-        while (true) {
+        while (c >= '0' && c <= '9') {
+          c -= '0';
+          precision = precision * 10 + c;
           c = *fmt++;
           if (c == 0) {
             return n;
           }
-          if (c >= '0' && c <= '9') {
-            c -= '0';
-            precision = precision * 10 + c;
-          }
-          else {
-            break;
-          }
         }
       }
     }
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chprintf enhancement

Post by Giovanni »

Fix committed thanks.

Giovanni
Post Reply