diff mbox

[U-Boot,01/18] tiny-printf: Always print zeroes

Message ID 1452011474-15207-2-git-send-email-sjg@chromium.org
State Accepted
Commit 74b1320ae535b9dfe6fb7a86e05a8787e503f59c
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass Jan. 5, 2016, 4:30 p.m. UTC
At present this does not print zero values in numeric format (hex and
decimal). Add a special case for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 lib/tiny-printf.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Comments

Stefan Roese Jan. 5, 2016, 5:08 p.m. UTC | #1
On 05.01.2016 17:30, Simon Glass wrote:
> At present this does not print zero values in numeric format (hex and
> decimal). Add a special case for this.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>   lib/tiny-printf.c | 16 ++++++++++++----
>   1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
> index efe5c25..a06abed 100644
> --- a/lib/tiny-printf.c
> +++ b/lib/tiny-printf.c
> @@ -82,13 +82,21 @@ int vprintf(const char *fmt, va_list va)
>   					num = -(int)num;
>   					out('-');
>   				}
> -				for (div = 1000000000; div; div /= 10)
> -					div_out(&num, div);
> +				if (!num) {
> +					out_dgt(0);
> +				} else {
> +					for (div = 1000000000; div; div /= 10)
> +						div_out(&num, div);
> +				}
>   				break;
>   			case 'x':
>   				num = va_arg(va, unsigned int);
> -				for (div = 0x10000000; div; div /= 0x10)
> -					div_out(&num, div);
> +				if (!num) {
> +					out_dgt(0);
> +				} else {
> +					for (div = 0x10000000; div; div /= 0x10)
> +						div_out(&num, div);
> +				}
>   				break;
>   			case 'c':
>   				out((char)(va_arg(va, int)));
>

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan
Tom Rini Jan. 13, 2016, 9:55 p.m. UTC | #2
On Tue, Jan 05, 2016 at 09:30:57AM -0700, Simon Glass wrote:

> At present this does not print zero values in numeric format (hex and
> decimal). Add a special case for this.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Tom Rini <trini@konsulko.com>
Simon Glass Jan. 16, 2016, 1:26 a.m. UTC | #3
On 13 January 2016 at 14:55, Tom Rini <trini@konsulko.com> wrote:
> On Tue, Jan 05, 2016 at 09:30:57AM -0700, Simon Glass wrote:
>
>> At present this does not print zero values in numeric format (hex and
>> decimal). Add a special case for this.
>>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>
> Reviewed-by: Tom Rini <trini@konsulko.com>
>
> --
> Tom

Applied to u-boot-dm
diff mbox

Patch

diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
index efe5c25..a06abed 100644
--- a/lib/tiny-printf.c
+++ b/lib/tiny-printf.c
@@ -82,13 +82,21 @@  int vprintf(const char *fmt, va_list va)
 					num = -(int)num;
 					out('-');
 				}
-				for (div = 1000000000; div; div /= 10)
-					div_out(&num, div);
+				if (!num) {
+					out_dgt(0);
+				} else {
+					for (div = 1000000000; div; div /= 10)
+						div_out(&num, div);
+				}
 				break;
 			case 'x':
 				num = va_arg(va, unsigned int);
-				for (div = 0x10000000; div; div /= 0x10)
-					div_out(&num, div);
+				if (!num) {
+					out_dgt(0);
+				} else {
+					for (div = 0x10000000; div; div /= 0x10)
+						div_out(&num, div);
+				}
 				break;
 			case 'c':
 				out((char)(va_arg(va, int)));