diff mbox series

[5/5] common/log.c: use vscnprintf() in log_dispatch()

Message ID 20210520100528.322846-6-rasmus.villemoes@prevas.dk
State Superseded
Delegated to: Tom Rini
Headers show
Series assorted printf-related patches | expand

Commit Message

Rasmus Villemoes May 20, 2021, 10:05 a.m. UTC
We have to use the *printf variant which returns the strlen() of the
resulting string, not the
how-much-would-have-been-printed-given-enough-space, in order to use
that value to inspect the last character in the string.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
 common/log.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Glass May 20, 2021, 5:51 p.m. UTC | #1
On Thu, 20 May 2021 at 04:05, Rasmus Villemoes
<rasmus.villemoes@prevas.dk> wrote:
>
> We have to use the *printf variant which returns the strlen() of the
> resulting string, not the
> how-much-would-have-been-printed-given-enough-space, in order to use
> that value to inspect the last character in the string.
>
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> ---
>  common/log.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

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

But I think it should check for a -ve value too.
diff mbox series

Patch

diff --git a/common/log.c b/common/log.c
index ea407c6db9..cba8df5caa 100644
--- a/common/log.c
+++ b/common/log.c
@@ -220,7 +220,7 @@  static int log_dispatch(struct log_rec *rec, const char *fmt, va_list args)
 			if (!rec->msg) {
 				int len;
 
-				len = vsnprintf(buf, sizeof(buf), fmt, args);
+				len = vscnprintf(buf, sizeof(buf), fmt, args);
 				rec->msg = buf;
 				gd->log_cont = len && buf[len - 1] != '\n';
 			}