Extra safety for sent->buflen when trimming whitespace
authorNick Downing <nick@ndcode.org>
Mon, 3 Jan 2022 01:40:11 +0000 (12:40 +1100)
committerNick Downing <nick@ndcode.org>
Mon, 3 Jan 2022 01:40:11 +0000 (12:40 +1100)
src/summarise.c

index 03f3484..ec70bd3 100644 (file)
@@ -149,7 +149,7 @@ static struct sentence *extract_finish(struct sentence *sent, struct persum *ps,
   enum index_summary_type type, int highlight) {
 #if 1 // Nick, do this first
     /* remove superfluous whitespace from the end of the sentence */
-    while (sent->buf[sent->buflen - 1] == ' ') {
+    while (sent->buflen && sent->buf[sent->buflen - 1] == ' ') {
         sent->buflen--;
     }
 #endif
@@ -186,7 +186,7 @@ static struct sentence *extract_finish(struct sentence *sent, struct persum *ps,
     }
 
     /* remove superfluous whitespace from the end of the sentence */
-    while (sent->buf[sent->buflen - 1] == ' ') {
+    while (sent->buflen && sent->buf[sent->buflen - 1] == ' ') {
         sent->buflen--;
     }
 #endif