diff mbox

[U-Boot,04/10] tiny-printf: Avoid printing NULL strings

Message ID 1451391772-6203-5-git-send-email-sjg@chromium.org
State Accepted
Commit 8e31681c5a5a2fd6bbdf751bcc900a4481e2fa29
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass Dec. 29, 2015, 12:22 p.m. UTC
Add a check for NULL strings to avoid printing junk to the console.

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

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

Comments

Stefan Roese Dec. 29, 2015, 1:23 p.m. UTC | #1
On 29.12.2015 13:22, Simon Glass wrote:
> Add a check for NULL strings to avoid printing junk to the console.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>   lib/tiny-printf.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
> index 403b134..efe5c25 100644
> --- a/lib/tiny-printf.c
> +++ b/lib/tiny-printf.c
> @@ -108,8 +108,10 @@ int vprintf(const char *fmt, va_list va)
>   				w--;
>   			while (w-- > 0)
>   				putc(lz ? '0' : ' ');
> -			while ((ch = *p++))
> -				putc(ch);
> +			if (p) {
> +				while ((ch = *p++))
> +					putc(ch);
> +			}
>   		}
>   	}
>
>

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

Thanks,
Stefan
Simon Glass Jan. 16, 2016, 1:25 a.m. UTC | #2
On 29 December 2015 at 06:23, Stefan Roese <sr@denx.de> wrote:
> On 29.12.2015 13:22, Simon Glass wrote:
>>
>> Add a check for NULL strings to avoid printing junk to the console.
>>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>> ---
>>
>>   lib/tiny-printf.c | 6 ++++--
>>   1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
>> index 403b134..efe5c25 100644
>> --- a/lib/tiny-printf.c
>> +++ b/lib/tiny-printf.c
>> @@ -108,8 +108,10 @@ int vprintf(const char *fmt, va_list va)
>>                                 w--;
>>                         while (w-- > 0)
>>                                 putc(lz ? '0' : ' ');
>> -                       while ((ch = *p++))
>> -                               putc(ch);
>> +                       if (p) {
>> +                               while ((ch = *p++))
>> +                                       putc(ch);
>> +                       }
>>                 }
>>         }
>>
>>
>
> Reviewed-by: Stefan Roese <sr@denx.de>

Applied to u-boot-dm
diff mbox

Patch

diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
index 403b134..efe5c25 100644
--- a/lib/tiny-printf.c
+++ b/lib/tiny-printf.c
@@ -108,8 +108,10 @@  int vprintf(const char *fmt, va_list va)
 				w--;
 			while (w-- > 0)
 				putc(lz ? '0' : ' ');
-			while ((ch = *p++))
-				putc(ch);
+			if (p) {
+				while ((ch = *p++))
+					putc(ch);
+			}
 		}
 	}