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.
steved
Posts: 626
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 5 times
Been thanked: 87 times

chprintf enhancement  Topic is solved

Postby steved » Thu Apr 19, 2018 1:20 pm

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 35 times

User avatar
Giovanni
Site Admin
Posts: 12290
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 590 times
Been thanked: 502 times
Contact:

Re: chprintf enhancement

Postby Giovanni » Sun Jan 06, 2019 4:59 pm

bump

steved
Posts: 626
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 5 times
Been thanked: 87 times

Re: chprintf enhancement

Postby steved » Fri May 31, 2019 11:13 am

Updated for 19.1
Attachments
chprintf.zip
(2.91 KiB) Downloaded 12 times

User avatar
Giovanni
Site Admin
Posts: 12290
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 590 times
Been thanked: 502 times
Contact:

Re: chprintf enhancement

Postby Giovanni » Fri May 31, 2019 1:22 pm

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: 197
Joined: Sun Jun 12, 2016 4:10 am
Location: Sydney, Australia
Has thanked: 77 times
Been thanked: 58 times

Re: chprintf enhancement

Postby FXCoder » Sun Jun 16, 2019 7:49 am

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: 12290
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 590 times
Been thanked: 502 times
Contact:

Re: chprintf enhancement

Postby Giovanni » Sun Jun 16, 2019 1:02 pm

Fix committed thanks.

Giovanni


Return to “Small Change Requests”

Who is online

Users browsing this forum: No registered users and 1 guest