git: 44debee9fc1f - stable/14 - rtld snprintf: do not erronously skip a char at the buffer boundary

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Fri, 03 May 2024 00:26:07 UTC
The branch stable/14 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=44debee9fc1fc795b928f75b5d894c3212d73893

commit 44debee9fc1fc795b928f75b5d894c3212d73893
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-04-28 06:37:24 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-05-03 00:25:33 +0000

    rtld snprintf: do not erronously skip a char at the buffer boundary
    
    (cherry picked from commit 56ee5fc43c40479e2651b21862e299bcf73017ae)
---
 libexec/rtld-elf/rtld_printf.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libexec/rtld-elf/rtld_printf.c b/libexec/rtld-elf/rtld_printf.c
index 07598c73c6d4..befac1c547b7 100644
--- a/libexec/rtld-elf/rtld_printf.c
+++ b/libexec/rtld-elf/rtld_printf.c
@@ -81,11 +81,10 @@ snprintf_func(int ch, struct snprintf_arg *const info)
 		}
 		break;
 	case PRINT_METHOD_WRITE:
-		if (info->remain > 0) {
-			*info->str++ = ch;
-			info->remain--;
-		} else
+		if (info->remain == 0)
 			printf_out(info);
+		*info->str++ = ch;
+		info->remain--;
 		break;
 	}
 }