From 17881c653f333baa15f9e7b735466a0333a6cee6 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 23 Jul 2026 22:12:42 -0300 Subject: fixed a couple bugs --- rat.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'rat.c') diff --git a/rat.c b/rat.c index 6c504ba..e713cc4 100644 --- a/rat.c +++ b/rat.c @@ -99,9 +99,10 @@ WINDOW *ratdrawbox(void){ } int wrapprint(WINDOW *win, int row, int col, int maxwidth, const char *msg){ + if(msg == NULL) return row; char copy[256]; - strncpy(copy, msg, sizeof(copy)); + strncpy(copy, msg, sizeof(copy) - 1); copy[sizeof(copy)-1] = '\0'; char line[256] = ""; @@ -117,8 +118,14 @@ int wrapprint(WINDOW *win, int row, int col, int maxwidth, const char *msg){ extra = 0; } - if(linelen > 0) strcat(line, " "); - strcat(line, word); + if(linelen > 0) { + if(strlen(line) + 1 < sizeof(line)) { + strcat(line, " "); + } + } + if(strlen(line) + strlen(word) < sizeof(line)) { + strcat(line, word); + } word = strtok(NULL, " "); } -- cgit v1.3-2-g0d8e