fmt_xlonglong was utterly broken (Johannes Vetter)
parent
f28b0ee6b2
commit
3c31c1a03b
@ -1,10 +1,17 @@
|
||||
#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) {
|
||||
int tmp=0;
|
||||
if (i>>32) {
|
||||
tmp=fmt_xlong(dest,i>>32);
|
||||
if (dest) dest+=tmp;
|
||||
}
|
||||
return tmp+fmt_xlong(dest,i&0xffffffff);
|
||||
unsigned long long len,tmp;
|
||||
/* first count the number of bytes needed */
|
||||
for (len=1, tmp=i; tmp>15; ++len) tmp>>=4;
|
||||
if (dest)
|
||||
for (tmp=i, dest+=len; ; ) {
|
||||
*--dest = tohex(tmp&15);
|
||||
if (!(tmp>>=4)) break;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
Loading…
Reference in New Issue