From 282b5da0c3d133fa7d6831e25a6729ebdcb02adc Mon Sep 17 00:00:00 2001 From: patacongo Date: Tue, 6 Mar 2007 21:35:03 +0000 Subject: [PATCH] Botched the case for n=0 git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@40 42af7a65-404d-4744-a932-0658087f49c3 --- lib/lib_libvsprintf.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/lib_libvsprintf.c b/lib/lib_libvsprintf.c index ebfd4dbea83..c4b34e7b6bd 100644 --- a/lib/lib_libvsprintf.c +++ b/lib/lib_libvsprintf.c @@ -270,15 +270,15 @@ static void utodec(struct lib_stream_s *obj, unsigned int n) static void utohex(struct lib_stream_s *obj, unsigned int n, ubyte a) { - boolean nonleading = FALSE; + boolean nonzero = FALSE; ubyte bits; for (bits = 8*sizeof(unsigned int); bits > 0; bits -= 4) { ubyte nibble = (ubyte)((n >> (bits - 4)) & 0xf); - if (nibble || nonleading) + if (nibble || nonzero) { - nonleading = TRUE; + nonzero = TRUE; if (nibble < 10) { @@ -290,6 +290,11 @@ static void utohex(struct lib_stream_s *obj, unsigned int n, ubyte a) } } } + + if (!nonzero) + { + obj->put(obj, '0'); + } } /************************************************************ @@ -518,15 +523,15 @@ static void lutodec(struct lib_stream_s *obj, unsigned long n) static void lutohex(struct lib_stream_s *obj, unsigned long n, ubyte a) { - boolean nonleading = FALSE; + boolean nonzero = FALSE; ubyte bits; for (bits = 8*sizeof(unsigned long); bits > 0; bits -= 4) { ubyte nibble = (ubyte)((n >> (bits - 4)) & 0xf); - if (nibble || nonleading) + if (nibble || nonzero) { - nonleading = TRUE; + nonzero = TRUE; if (nibble < 10) { @@ -538,6 +543,11 @@ static void lutohex(struct lib_stream_s *obj, unsigned long n, ubyte a) } } } + + if (!nonzero) + { + obj->put(obj, '0'); + } } /************************************************************ @@ -763,15 +773,15 @@ static void llutodec(struct lib_stream_s *obj, unsigned long long n) static void llutohex(struct lib_stream_s *obj, unsigned long long n, ubyte a) { - boolean nonleading = FALSE; + boolean nonzero = FALSE; ubyte bits; for (bits = 8*sizeof(unsigned long long); bits > 0; bits -= 4) { ubyte nibble = (ubyte)((n >> (bits - 4)) & 0xf); - if (nibble || nonleading) + if (nibble || nonzero) { - nonleading = TRUE; + nonzero = TRUE; if (nibble < 10) { @@ -783,6 +793,11 @@ static void llutohex(struct lib_stream_s *obj, unsigned long long n, ubyte a) } } } + + if (!nonzero) + { + obj->put(obj, '0'); + } } /************************************************************