fmt_xlonglong was utterly broken (Johannes Vetter)
parent
f28b0ee6b2
commit
3c31c1a03b
@ -1,10 +1,17 @@
|
|||||||
#include "fmt.h"
|
#include "fmt.h"
|
||||||
|
|
||||||
|
static inline char tohex(char c) {
|
||||||
|
return c>=10?c-10+'a':c+'0';
|
||||||
|
}
|
||||||
|
|
||||||
size_t fmt_xlonglong(char *dest,unsigned long long i) {
|
size_t fmt_xlonglong(char *dest,unsigned long long i) {
|
||||||
int tmp=0;
|
unsigned long long len,tmp;
|
||||||
if (i>>32) {
|
/* first count the number of bytes needed */
|
||||||
tmp=fmt_xlong(dest,i>>32);
|
for (len=1, tmp=i; tmp>15; ++len) tmp>>=4;
|
||||||
if (dest) dest+=tmp;
|
if (dest)
|
||||||
|
for (tmp=i, dest+=len; ; ) {
|
||||||
|
*--dest = tohex(tmp&15);
|
||||||
|
if (!(tmp>>=4)) break;
|
||||||
}
|
}
|
||||||
return tmp+fmt_xlong(dest,i&0xffffffff);
|
return len;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue