diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-03-06 21:35:03 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-03-06 21:35:03 +0000 |
commit | 37d122462b63f86d33120783576e9b74b880edd9 (patch) | |
tree | f48d59eff3125e52f78a429eb4c03a15c5898bb6 /nuttx/lib | |
parent | 51341b9f7069bc9c18a18cb8e4e7f66a3a27365a (diff) | |
download | px4-nuttx-37d122462b63f86d33120783576e9b74b880edd9.tar.gz px4-nuttx-37d122462b63f86d33120783576e9b74b880edd9.tar.bz2 px4-nuttx-37d122462b63f86d33120783576e9b74b880edd9.zip |
Botched the case for n=0
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@40 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/lib')
-rw-r--r-- | nuttx/lib/lib_libvsprintf.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/nuttx/lib/lib_libvsprintf.c b/nuttx/lib/lib_libvsprintf.c index ebfd4dbea..c4b34e7b6 100644 --- a/nuttx/lib/lib_libvsprintf.c +++ b/nuttx/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'); + } } /************************************************************ |