[PATCH 2/2] commands: edit: remove the memset call on screenline

Jules Maselbas jmaselbas at zdiv.net
Mon Mar 31 10:40:50 PDT 2025


Rework the screenline function so the lbuf doesn't have to be
initialized to zero eachtime the screenline function is called.

Signed-off-by: Jules Maselbas <jmaselbas at zdiv.net>
---
 commands/edit.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/commands/edit.c b/commands/edit.c
index 3bbe60fdbf..28c9ab8877 100644
--- a/commands/edit.c
+++ b/commands/edit.c
@@ -46,11 +46,9 @@ static char *screenline(char *line, int *pos)
 	int i, outpos = 0;
 	static char lbuf[1024];
 
-	memset(lbuf, 0, 1024);
-
 	if (!line) {
-		lbuf[0] = '~';
-		return lbuf;
+		lbuf[outpos++] = '~';
+		goto out;
 	}
 
 	for (i = 0; outpos < sizeof(lbuf) - 1; i++) {
@@ -67,6 +65,8 @@ static char *screenline(char *line, int *pos)
 		lbuf[outpos++] = line[i];
 	}
 
+out:
+	lbuf[outpos] = 0;
 	return lbuf;
 }
 
-- 
2.48.1




More information about the barebox mailing list