From 3f98d20ce1b9d72d689fb1a10a5f1605fef00a1a Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Tue, 14 Apr 2020 13:30:34 +0000
Subject: [PATCH] Fix fencepost error detected by Coverity...

Because the test to continue is *after* the loop, we can't continue
when c is the last index into lzh->son, or the code will make use of
lzh->son[sizeof(lzh->son)/sizeof(lzh->son[0])] which is outside the bounds
of the array.
---
 src/encode/lzh.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/encode/lzh.c b/src/encode/lzh.c
index 77a84f90e6..70e7447c83 100644
--- a/src/encode/lzh.c
+++ b/src/encode/lzh.c
@@ -468,7 +468,7 @@ static void lzh_update(lzh_t* lzh, short int c)
 
 			c = l;
 		}
-	} while (((c = lzh->prnt[c]) != 0) && c < (sizeof(lzh->son)/sizeof(lzh->son[0])));	/* do it until reaching the root */
+	} while (((c = lzh->prnt[c]) != 0) && c < ((sizeof(lzh->son)/sizeof(lzh->son[0]))-1));	/* do it until reaching the root */
 }
 
 static void lzh_encode_char(lzh_t* lzh, unsigned short c, uint8_t *outbuf, int32_t *outlen)
-- 
GitLab