diary

Text-based journaling program
git clone https://git.in0rdr.ch/diary.git
Log | Files | Refs | Pull requests | README | LICENSE

commit 1165944b85015174e256c55149a115a20fd16b44
parent 9e77f9028ee159cbe74a618499c8ee194ef9f150
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Sun,  8 Sep 2024 01:17:49 +0200

fix(103-folding): make room for cr

Diffstat:
Msrc/utils.c | 17+++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/utils.c b/src/utils.c @@ -102,12 +102,21 @@ char* fold(const char* str) { } buf = (char*) newbuf; - if ((bufl > 1) && ((bufl % 77) == 0)) { - // break lines after 75 chars + // break lines after 75 chars + if ((bufl > 2) && ((bufl % 77) == 0)) { + // make room for the cr (\r) below + newbuf = realloc(buf, ++bufl); + if (newbuf == NULL) { + perror("realloc failed"); + free(buf); + return NULL; + } + buf = (char*) newbuf; + // split between any two characters by inserting a CRLF // immediately followed by a white space character - buf[bufl-2] = '\r'; - buf[bufl-1] = '\n'; + buf[bufl-3] = '\r'; + buf[bufl-2] = '\n'; escch = ' '; esc = true; continue;