git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 17:17 UTC

[PATCH 4/6] xdiff: avoid signed vs. unsigned comparisons in xhistogram.c

From
David Aguilar <davvid@gmail.com>
Date
Feb 12, 2025, 06:04 UTC
Message-ID
<20250212060418.1645241-4-davvid@gmail.com>
In-Reply-To
<20250212060418.1645241-1-davvid@gmail.com>

The comparisons all involve unsigned variables. Cast the comparison to unsigned to eliminate the mismatch.

Signed-off-by: David Aguilar <davvid@gmail.com>
---
 xdiff/xhistogram.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/xdiff/xhistogram.c b/xdiff/xhistogram.c
index 3d2b190fa6..040d81e0bc 100644
--- a/xdiff/xhistogram.c
+++ b/xdiff/xhistogram.c
@@ -41,8 +41,6 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#define DISABLE_SIGN_COMPARE_WARNINGS
-
 #include "xinclude.h"
 
 #define MAX_PTR	UINT_MAX
@@ -108,7 +106,7 @@ static int scanA(struct histindex *index, int line1, int count1)
 	unsigned int chain_len;
 	struct record **rec_chain, *rec;
 
-	for (ptr = LINE_END(1); line1 <= ptr; ptr--) {
+	for (ptr = LINE_END(1); (unsigned int)line1 <= ptr; ptr--) {
 		tbl_idx = TABLE_HASH(index, 1, ptr);
 		rec_chain = index->records + tbl_idx;
 		rec = *rec_chain;
@@ -183,14 +181,14 @@ static int try_lcs(struct histindex *index, struct region *lcs, int b_ptr,
 			be = bs;
 			rc = rec->cnt;
 
-			while (line1 < as && line2 < bs
+			while ((unsigned int)line1 < as && (unsigned int)line2 < bs
 				&& CMP(index, 1, as - 1, 2, bs - 1)) {
 				as--;
 				bs--;
 				if (1 < rc)
 					rc = XDL_MIN(rc, CNT(index, as));
 			}
-			while (ae < LINE_END(1) && be < LINE_END(2)
+			while (ae < (unsigned int)LINE_END(1) && be < (unsigned int)LINE_END(2)
 				&& CMP(index, 1, ae + 1, 2, be + 1)) {
 				ae++;
 				be++;
@@ -315,7 +313,7 @@ static int histogram_diff(xpparam_t const *xpp, xdfenv_t *env,
 	if (count1 <= 0 && count2 <= 0)
 		return 0;
 
-	if (LINE_END(1) >= MAX_PTR)
+	if ((unsigned int)LINE_END(1) >= MAX_PTR)
 		return -1;
 
 	if (!count1) {
-- 
2.48.1.643.g61982db19f
Previous: David AguilarNext: David Aguilar
Message 4 of 6 in “xdiff: move sign comparison warning guard into each file”
  1. 1/6 xdiff: move sign comparison warning guard into each fileDavid Aguilar, Feb 12, 2025
  2. 2/6 xdiff: avoid signed vs. unsigned comparisons in xdiffi.cDavid Aguilar, Feb 12, 2025
  3. 3/6 xdiff: avoid signed vs. unsigned comparisons in xemit.cDavid Aguilar, Feb 12, 2025
  4. 4/6 xdiff: avoid signed vs. unsigned comparisons in xhistogram.cDavid Aguilar, Feb 12, 2025
  5. 5/6 xdiff: avoid signed vs. unsigned comparisons in xpatience.cDavid Aguilar, Feb 12, 2025
  6. 6/6 xdiff: avoid signed vs. unsigned comparisons in xutils.cDavid Aguilar, Feb 12, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.