]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1926: xdiff: Coverity warning with MAX_CNT/UINT_MAX usage v9.1.1926
authorYee Cheng Chin <ychin.git@gmail.com>
Sun, 23 Nov 2025 19:24:10 +0000 (19:24 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 23 Nov 2025 19:24:10 +0000 (19:24 +0000)
Problem:  xdiff: Coverity warning with MAX_CNT/UINT_MAX usage
          (after v9.1.1921)
Solution: Replace XDL_MIN macro to a manual check.
          (Yee Cheng Chin)

In the recent xdiff upstream sync (#18765), MAX_CNT in xhistogram was
switched back to using UINT_MAX to match upstream. This exposed an issue
in xdiff that using using min() to compare against the max integer will
not work as the number will just overflow. Switch the check to be done
in a saturating add that respects integer overflow.

related: #18765
closes: #18792

Signed-off-by: Yee Cheng Chin <ychin.git@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/version.c
src/xdiff/xhistogram.c

index a02a9e2d84a46e1075e49dc6a06fd8bf051b0eee..b34018b852f7e2be53f81386b4311b444c126c6a 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1926,
 /**/
     1925,
 /**/
index 6dc450b1fe1dfc2c85d7acf98c948581b48e6f28..50f208c9f0d13dbbafdd0dfba6786a67b5f611f6 100644 (file)
@@ -122,7 +122,7 @@ static int scanA(struct histindex *index, int line1, int count1)
                                NEXT_PTR(index, ptr) = rec->ptr;
                                rec->ptr = ptr;
                                /* cap rec->cnt at MAX_CNT */
-                               rec->cnt = XDL_MIN(MAX_CNT, rec->cnt + 1);
+                               rec->cnt = (rec->cnt < MAX_CNT) ? rec->cnt + 1 : rec->cnt;
                                LINE_MAP(index, ptr) = rec;
                                goto continue_scan;
                        }