All pastes #400195 Raw Edit

Something

public text v1 · immutable
#400195 ·published 2007-03-18 15:38 UTC
rendered paste body
Index: firmware/common/sprintf.c
===================================================================
--- firmware/common/sprintf.c	(revision 12823)
+++ firmware/common/sprintf.c	(working copy)
@@ -42,7 +42,7 @@
 {
     char *str;
     char tmpbuf[12], pad;
-    int ch, width, val, sign;
+    int ch, width, val, sign, precision;
     long lval, lsign;
     unsigned int uval;
     unsigned long ulval;
@@ -65,6 +65,17 @@
         width = 10*width + ch - '0';
         ch = *fmt++;
         }
+        
+        precision = 0;
+        if(ch == '.')
+        {
+            ch = *fmt++;
+            while (ch >= '0' && ch <= '9')
+            {
+                precision = 10*precision + ch - '0';
+                ch = *fmt++;
+            }
+        }
 
         str = tmpbuf + sizeof tmpbuf - 1;
         switch (ch)
@@ -75,6 +86,8 @@
 
         case 's':
             str = va_arg (ap, char*);
+            if(precision > 0)
+                str[precision] = '\0';
             break;
 
         case 'd':