]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - lib/vsprintf.c
Merge tag 'module-for-3.4' of git://git.kernel.org/pub/scm/linux/kernel/git/paulg...
[karo-tx-linux.git] / lib / vsprintf.c
index 7f29bfce840256d9b2b664fc79341d04e06a46d0..abbabec9720a1947ffa5364ae9aab9ec9696ecfe 100644 (file)
@@ -212,6 +212,26 @@ char *put_dec(char *buf, unsigned long long num)
        }
 }
 
+/*
+ * Convert passed number to decimal string.
+ * Returns the length of string.  On buffer overflow, returns 0.
+ *
+ * If speed is not important, use snprintf(). It's easy to read the code.
+ */
+int num_to_str(char *buf, int size, unsigned long long num)
+{
+       char tmp[21];           /* Enough for 2^64 in decimal */
+       int idx, len;
+
+       len = put_dec(tmp, num) - tmp;
+
+       if (len > size)
+               return 0;
+       for (idx = 0; idx < len; ++idx)
+               buf[idx] = tmp[len - idx - 1];
+       return  len;
+}
+
 #define ZEROPAD        1               /* pad with zero */
 #define SIGN   2               /* unsigned/signed long */
 #define PLUS   4               /* show plus */
@@ -891,9 +911,15 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
        case 'U':
                return uuid_string(buf, end, ptr, spec, fmt);
        case 'V':
-               return buf + vsnprintf(buf, end > buf ? end - buf : 0,
-                                      ((struct va_format *)ptr)->fmt,
-                                      *(((struct va_format *)ptr)->va));
+               {
+                       va_list va;
+
+                       va_copy(va, *((struct va_format *)ptr)->va);
+                       buf += vsnprintf(buf, end > buf ? end - buf : 0,
+                                        ((struct va_format *)ptr)->fmt, va);
+                       va_end(va);
+                       return buf;
+               }
        case 'K':
                /*
                 * %pK cannot be used in IRQ context because its test