summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nuttx/lib/lib_libvsprintf.c33
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');
+ }
}
/************************************************************