diff --git a/fmt/fmt_8long.c b/fmt/fmt_8long.c index 749832f..a74b00c 100644 --- a/fmt/fmt_8long.c +++ b/fmt/fmt_8long.c @@ -5,7 +5,9 @@ unsigned int fmt_8long(char *dest,unsigned long i) { /* first count the number of bytes needed */ for (len=1, tmp=i; tmp>7; ++len) tmp/=8; if (dest) - for (tmp=i, dest+=len; tmp; tmp/=8) + for (tmp=i, dest+=len; ; ) { *--dest = (tmp&7)+'0'; + if (!(tmp>>=3)) break; + } return len; } diff --git a/fmt/fmt_xlong.c b/fmt/fmt_xlong.c index 2f71c3a..6a35aa4 100644 --- a/fmt/fmt_xlong.c +++ b/fmt/fmt_xlong.c @@ -9,7 +9,9 @@ unsigned int fmt_xlong(char *dest,unsigned long i) { /* first count the number of bytes needed */ for (len=1, tmp=i; tmp>15; ++len) tmp>>=4; if (dest) - for (tmp=i, dest+=len; tmp; tmp>>=4) + for (tmp=i, dest+=len; ; ) { *--dest = tohex(tmp&15); + if (!(tmp>>=4)) break; + } return len; }