Commit bf05293973b348f6946c9df92cd3c65ece42d0be

Authored by James Yang
Committed by Wolfgang Denk
1 parent 92fa37eac5

Fix 64-bit vsprintf.

There were some size and unsigned problems.
Also add support for "ll" size modifier in format string like glibc

Signed-off-by: James Yang <James.Yang@freescale.com>
Acked-by: Jon Loeliger <jdl@freescale.com>

Showing 1 changed file with 17 additions and 4 deletions Side-by-side Diff

lib_generic/vsprintf.c
... ... @@ -105,17 +105,26 @@
105 105 #define SPECIAL 32 /* 0x */
106 106 #define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */
107 107  
  108 +#ifdef CFG_64BIT_VSPRINTF
108 109 #define do_div(n,base) ({ \
  110 + unsigned int __res; \
  111 + __res = ((unsigned long long) n) % base; \
  112 + n = ((unsigned long long) n) / base; \
  113 + __res; \
  114 +})
  115 +#else
  116 +#define do_div(n,base) ({ \
109 117 int __res; \
110   - __res = ((unsigned long) n) % (unsigned) base; \
111   - n = ((unsigned long) n) / (unsigned) base; \
  118 + __res = ((unsigned long) n) % base; \
  119 + n = ((unsigned long) n) / base; \
112 120 __res; \
113 121 })
  122 +#endif
114 123  
115 124 #ifdef CFG_64BIT_VSPRINTF
116   -static char * number(char * str, long long num, int base, int size, int precision ,int type)
  125 +static char * number(char * str, long long num, unsigned int base, int size, int precision ,int type)
117 126 #else
118   -static char * number(char * str, long num, int base, int size, int precision ,int type)
  127 +static char * number(char * str, long num, unsigned int base, int size, int precision ,int type)
119 128 #endif
120 129 {
121 130 char c,sign,tmp[66];
... ... @@ -255,6 +264,10 @@
255 264 qualifier = -1;
256 265 if (*fmt == 'h' || *fmt == 'l' || *fmt == 'q') {
257 266 qualifier = *fmt;
  267 + if (qualifier == 'l' && *(fmt+1) == 'l') {
  268 + qualifier = 'q';
  269 + ++fmt;
  270 + }
258 271 ++fmt;
259 272 }
260 273