{"thread":{"id":"62941","subject":"[PATCH 1/6] xdiff: move sign comparison warning guard into each file","startedAt":"2025-02-12T06:04:21Z","lastAt":"2025-02-12T06:04:28Z","messageCount":6,"participants":["David Aguilar"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"512287","messageId":"20250212060418.1645241-1-davvid@gmail.com","threadId":"62941","inReplyTo":null,"subject":"[PATCH 1/6] xdiff: move sign comparison warning guard into each file","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2025-02-12T06:04:13Z","receivedAt":"2025-02-12T06:04:21Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"Allow each file to fix the warnings guarded by the macro separately by\nmoving the definition from the shared xinclude.h into each file that\nneeds it.\n\nxmerge.c and xprepare.c do not contain any signed vs. unsigned\ncomparisons so the definition was not included in these files.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n xdiff/xemit.c      | 2 ++\n xdiff/xhistogram.c | 2 ++\n xdiff/xinclude.h   | 2 --\n xdiff/xpatience.c  | 3 +++\n xdiff/xutils.c     | 2 ++\n 5 files changed, 9 insertions(+), 2 deletions(-)\n\ndiff --git a/xdiff/xemit.c b/xdiff/xemit.c\nindex 75f0fe4986..2b394a4806 100644\n--- a/xdiff/xemit.c\n+++ b/xdiff/xemit.c\n@@ -20,6 +20,8 @@\n  *\n  */\n \n+#define DISABLE_SIGN_COMPARE_WARNINGS\n+\n #include \"xinclude.h\"\n \n static long xdl_get_rec(xdfile_t *xdf, long ri, char const **rec) {\ndiff --git a/xdiff/xhistogram.c b/xdiff/xhistogram.c\nindex 16a8fe2f3f..3d2b190fa6 100644\n--- a/xdiff/xhistogram.c\n+++ b/xdiff/xhistogram.c\n@@ -41,6 +41,8 @@\n  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n  */\n \n+#define DISABLE_SIGN_COMPARE_WARNINGS\n+\n #include \"xinclude.h\"\n \n #define MAX_PTR\tUINT_MAX\ndiff --git a/xdiff/xinclude.h b/xdiff/xinclude.h\nindex 7e56542526..a4285ac0eb 100644\n--- a/xdiff/xinclude.h\n+++ b/xdiff/xinclude.h\n@@ -23,8 +23,6 @@\n #if !defined(XINCLUDE_H)\n #define XINCLUDE_H\n \n-#define DISABLE_SIGN_COMPARE_WARNINGS\n-\n #include \"git-compat-util.h\"\n #include \"xmacros.h\"\n #include \"xdiff.h\"\ndiff --git a/xdiff/xpatience.c b/xdiff/xpatience.c\nindex a2d8955537..b0ba421b28 100644\n--- a/xdiff/xpatience.c\n+++ b/xdiff/xpatience.c\n@@ -19,6 +19,9 @@\n  *  Davide Libenzi <davidel@xmailserver.org>\n  *\n  */\n+\n+#define DISABLE_SIGN_COMPARE_WARNINGS\n+\n #include \"xinclude.h\"\n \n /*\ndiff --git a/xdiff/xutils.c b/xdiff/xutils.c\nindex 9e36f24875..169edff5ab 100644\n--- a/xdiff/xutils.c\n+++ b/xdiff/xutils.c\n@@ -20,6 +20,8 @@\n  *\n  */\n \n+#define DISABLE_SIGN_COMPARE_WARNINGS\n+\n #include \"xinclude.h\"\n \n \n-- \n2.48.1.643.g61982db19f\n\n"},{"id":"512288","messageId":"20250212060418.1645241-2-davvid@gmail.com","threadId":"62941","inReplyTo":"20250212060418.1645241-1-davvid@gmail.com","subject":"[PATCH 2/6] xdiff: avoid signed vs. unsigned comparisons in xdiffi.c","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2025-02-12T06:04:14Z","receivedAt":"2025-02-12T06:04:23Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"The loop iteration variable is non-negative and only used in comparisons\nagainst other size_t values.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n xdiff/xdiffi.c | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/xdiff/xdiffi.c b/xdiff/xdiffi.c\nindex 4685ba6137..8889b8b62a 100644\n--- a/xdiff/xdiffi.c\n+++ b/xdiff/xdiffi.c\n@@ -19,7 +19,6 @@\n  *  Davide Libenzi <davidel@xmailserver.org>\n  *\n  */\n-#define DISABLE_SIGN_COMPARE_WARNINGS\n \n #include \"xinclude.h\"\n \n@@ -1014,7 +1013,7 @@ static void xdl_mark_ignorable_lines(xdchange_t *xscr, xdfenv_t *xe, long flags)\n \n static int record_matches_regex(xrecord_t *rec, xpparam_t const *xpp) {\n \tregmatch_t regmatch;\n-\tint i;\n+\tsize_t i;\n \n \tfor (i = 0; i < xpp->ignore_regex_nr; i++)\n \t\tif (!regexec_buf(xpp->ignore_regex[i], rec->ptr, rec->size, 1,\n-- \n2.48.1.643.g61982db19f\n\n"},{"id":"512289","messageId":"20250212060418.1645241-3-davvid@gmail.com","threadId":"62941","inReplyTo":"20250212060418.1645241-1-davvid@gmail.com","subject":"[PATCH 3/6] xdiff: avoid signed vs. unsigned comparisons in xemit.c","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2025-02-12T06:04:15Z","receivedAt":"2025-02-12T06:04:24Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"The unsigned `ignored` variable causes expressions to promote to\nunsigned. Use a signed value to make comparisons use the same types.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n xdiff/xemit.c | 4 +---\n 1 file changed, 1 insertion(+), 3 deletions(-)\n\ndiff --git a/xdiff/xemit.c b/xdiff/xemit.c\nindex 2b394a4806..f8e3f25b03 100644\n--- a/xdiff/xemit.c\n+++ b/xdiff/xemit.c\n@@ -20,8 +20,6 @@\n  *\n  */\n \n-#define DISABLE_SIGN_COMPARE_WARNINGS\n-\n #include \"xinclude.h\"\n \n static long xdl_get_rec(xdfile_t *xdf, long ri, char const **rec) {\n@@ -56,7 +54,7 @@ xdchange_t *xdl_get_hunk(xdchange_t **xscr, xdemitconf_t const *xecfg)\n \txdchange_t *xch, *xchp, *lxch;\n \tlong max_common = 2 * xecfg->ctxlen + xecfg->interhunkctxlen;\n \tlong max_ignorable = xecfg->ctxlen;\n-\tunsigned long ignored = 0; /* number of ignored blank lines */\n+\tlong ignored = 0; /* number of ignored blank lines */\n \n \t/* remove ignorable changes that are too far before other changes */\n \tfor (xchp = *xscr; xchp && xchp->ignore; xchp = xchp->next) {\n-- \n2.48.1.643.g61982db19f\n\n"},{"id":"512290","messageId":"20250212060418.1645241-4-davvid@gmail.com","threadId":"62941","inReplyTo":"20250212060418.1645241-1-davvid@gmail.com","subject":"[PATCH 4/6] xdiff: avoid signed vs. unsigned comparisons in xhistogram.c","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2025-02-12T06:04:16Z","receivedAt":"2025-02-12T06:04:25Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"The comparisons all involve unsigned variables. Cast the comparison\nto unsigned to eliminate the mismatch.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n xdiff/xhistogram.c | 10 ++++------\n 1 file changed, 4 insertions(+), 6 deletions(-)\n\ndiff --git a/xdiff/xhistogram.c b/xdiff/xhistogram.c\nindex 3d2b190fa6..040d81e0bc 100644\n--- a/xdiff/xhistogram.c\n+++ b/xdiff/xhistogram.c\n@@ -41,8 +41,6 @@\n  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n  */\n \n-#define DISABLE_SIGN_COMPARE_WARNINGS\n-\n #include \"xinclude.h\"\n \n #define MAX_PTR\tUINT_MAX\n@@ -108,7 +106,7 @@ static int scanA(struct histindex *index, int line1, int count1)\n \tunsigned int chain_len;\n \tstruct record **rec_chain, *rec;\n \n-\tfor (ptr = LINE_END(1); line1 <= ptr; ptr--) {\n+\tfor (ptr = LINE_END(1); (unsigned int)line1 <= ptr; ptr--) {\n \t\ttbl_idx = TABLE_HASH(index, 1, ptr);\n \t\trec_chain = index->records + tbl_idx;\n \t\trec = *rec_chain;\n@@ -183,14 +181,14 @@ static int try_lcs(struct histindex *index, struct region *lcs, int b_ptr,\n \t\t\tbe = bs;\n \t\t\trc = rec->cnt;\n \n-\t\t\twhile (line1 < as && line2 < bs\n+\t\t\twhile ((unsigned int)line1 < as && (unsigned int)line2 < bs\n \t\t\t\t&& CMP(index, 1, as - 1, 2, bs - 1)) {\n \t\t\t\tas--;\n \t\t\t\tbs--;\n \t\t\t\tif (1 < rc)\n \t\t\t\t\trc = XDL_MIN(rc, CNT(index, as));\n \t\t\t}\n-\t\t\twhile (ae < LINE_END(1) && be < LINE_END(2)\n+\t\t\twhile (ae < (unsigned int)LINE_END(1) && be < (unsigned int)LINE_END(2)\n \t\t\t\t&& CMP(index, 1, ae + 1, 2, be + 1)) {\n \t\t\t\tae++;\n \t\t\t\tbe++;\n@@ -315,7 +313,7 @@ static int histogram_diff(xpparam_t const *xpp, xdfenv_t *env,\n \tif (count1 <= 0 && count2 <= 0)\n \t\treturn 0;\n \n-\tif (LINE_END(1) >= MAX_PTR)\n+\tif ((unsigned int)LINE_END(1) >= MAX_PTR)\n \t\treturn -1;\n \n \tif (!count1) {\n-- \n2.48.1.643.g61982db19f\n\n"},{"id":"512291","messageId":"20250212060418.1645241-5-davvid@gmail.com","threadId":"62941","inReplyTo":"20250212060418.1645241-1-davvid@gmail.com","subject":"[PATCH 5/6] xdiff: avoid signed vs. unsigned comparisons in xpatience.c","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2025-02-12T06:04:17Z","receivedAt":"2025-02-12T06:04:27Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"The loop iteration variable is non-negative and used in comparisons\nagainst a size_t value. Use size_t to eliminate the mismatch.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n xdiff/xpatience.c | 4 +---\n 1 file changed, 1 insertion(+), 3 deletions(-)\n\ndiff --git a/xdiff/xpatience.c b/xdiff/xpatience.c\nindex b0ba421b28..82f663004e 100644\n--- a/xdiff/xpatience.c\n+++ b/xdiff/xpatience.c\n@@ -20,8 +20,6 @@\n  *\n  */\n \n-#define DISABLE_SIGN_COMPARE_WARNINGS\n-\n #include \"xinclude.h\"\n \n /*\n@@ -78,7 +76,7 @@ struct hashmap {\n \n static int is_anchor(xpparam_t const *xpp, const char *line)\n {\n-\tint i;\n+\tsize_t i;\n \tfor (i = 0; i < xpp->anchors_nr; i++) {\n \t\tif (!strncmp(line, xpp->anchors[i], strlen(xpp->anchors[i])))\n \t\t\treturn 1;\n-- \n2.48.1.643.g61982db19f\n\n"},{"id":"512292","messageId":"20250212060418.1645241-6-davvid@gmail.com","threadId":"62941","inReplyTo":"20250212060418.1645241-1-davvid@gmail.com","subject":"[PATCH 6/6] xdiff: avoid signed vs. unsigned comparisons in xutils.c","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2025-02-12T06:04:18Z","receivedAt":"2025-02-12T06:04:28Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"The comparisons all involve comparisons against unsigned values.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n xdiff/xutils.c | 6 ++----\n 1 file changed, 2 insertions(+), 4 deletions(-)\n\ndiff --git a/xdiff/xutils.c b/xdiff/xutils.c\nindex 169edff5ab..444a108f87 100644\n--- a/xdiff/xutils.c\n+++ b/xdiff/xutils.c\n@@ -20,8 +20,6 @@\n  *\n  */\n \n-#define DISABLE_SIGN_COMPARE_WARNINGS\n-\n #include \"xinclude.h\"\n \n \n@@ -377,7 +375,7 @@ static int xdl_format_hunk_hdr(long s1, long c1, long s2, long c2,\n \tnb += 3;\n \tif (func && funclen) {\n \t\tbuf[nb++] = ' ';\n-\t\tif (funclen > sizeof(buf) - nb - 1)\n+\t\tif ((size_t)funclen > sizeof(buf) - nb - 1)\n \t\t\tfunclen = sizeof(buf) - nb - 1;\n \t\tmemcpy(buf + nb, func, funclen);\n \t\tnb += funclen;\n@@ -439,7 +437,7 @@ void* xdl_alloc_grow_helper(void *p, long nr, long *alloc, size_t size)\n {\n \tvoid *tmp = NULL;\n \tsize_t n = ((LONG_MAX - 16) / 2 >= *alloc) ? 2 * *alloc + 16 : LONG_MAX;\n-\tif (nr > n)\n+\tif ((size_t)nr > n)\n \t\tn = nr;\n \tif (SIZE_MAX / size >= n)\n \t\ttmp = xdl_realloc(p, n * size);\n-- \n2.48.1.643.g61982db19f\n\n"}]}