From 6eca5174a8f8d641f9b19dee544a57ea57ad19a5 Mon Sep 17 00:00:00 2001 From: leitner Date: Mon, 23 Apr 2001 13:41:17 +0000 Subject: [PATCH] fix outputting 0. --- fmt/fmt_8long.c | 4 +++- fmt/fmt_xlong.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) 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; }