Skip to content

Commit

Permalink
Merge branch 'da/xdiff-w-sign-compare-workaround' into seen
Browse files Browse the repository at this point in the history
* da/xdiff-w-sign-compare-workaround:
  xdiff: avoid signed vs. unsigned comparisons in xutils.c
  xdiff: avoid signed vs. unsigned comparisons in xpatience.c
  xdiff: avoid signed vs. unsigned comparisons in xhistogram.c
  xdiff: avoid signed vs. unsigned comparisons in xemit.c
  xdiff: avoid signed vs. unsigned comparisons in xdiffi.c
  xdiff: move sign comparison warning guard into each file
  • Loading branch information
gitster committed Feb 12, 2025
2 parents a4b649a + a3b56f5 commit 8ff1fb3
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 12 deletions.
3 changes: 1 addition & 2 deletions xdiff/xdiffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* Davide Libenzi <[email protected]>
*
*/
#define DISABLE_SIGN_COMPARE_WARNINGS

#include "xinclude.h"

Expand Down Expand Up @@ -1014,7 +1013,7 @@ static void xdl_mark_ignorable_lines(xdchange_t *xscr, xdfenv_t *xe, long flags)

static int record_matches_regex(xrecord_t *rec, xpparam_t const *xpp) {
regmatch_t regmatch;
int i;
size_t i;

for (i = 0; i < xpp->ignore_regex_nr; i++)
if (!regexec_buf(xpp->ignore_regex[i], rec->ptr, rec->size, 1,
Expand Down
2 changes: 1 addition & 1 deletion xdiff/xemit.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ xdchange_t *xdl_get_hunk(xdchange_t **xscr, xdemitconf_t const *xecfg)
xdchange_t *xch, *xchp, *lxch;
long max_common = 2 * xecfg->ctxlen + xecfg->interhunkctxlen;
long max_ignorable = xecfg->ctxlen;
unsigned long ignored = 0; /* number of ignored blank lines */
long ignored = 0; /* number of ignored blank lines */

/* remove ignorable changes that are too far before other changes */
for (xchp = *xscr; xchp && xchp->ignore; xchp = xchp->next) {
Expand Down
8 changes: 4 additions & 4 deletions xdiff/xhistogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,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;
Expand Down Expand Up @@ -181,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++;
Expand Down Expand Up @@ -313,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) {
Expand Down
2 changes: 0 additions & 2 deletions xdiff/xinclude.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#if !defined(XINCLUDE_H)
#define XINCLUDE_H

#define DISABLE_SIGN_COMPARE_WARNINGS

#include "git-compat-util.h"
#include "xmacros.h"
#include "xdiff.h"
Expand Down
3 changes: 2 additions & 1 deletion xdiff/xpatience.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Davide Libenzi <[email protected]>
*
*/

#include "xinclude.h"

/*
Expand Down Expand Up @@ -75,7 +76,7 @@ struct hashmap {

static int is_anchor(xpparam_t const *xpp, const char *line)
{
int i;
size_t i;
for (i = 0; i < xpp->anchors_nr; i++) {
if (!strncmp(line, xpp->anchors[i], strlen(xpp->anchors[i])))
return 1;
Expand Down
4 changes: 2 additions & 2 deletions xdiff/xutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ static int xdl_format_hunk_hdr(long s1, long c1, long s2, long c2,
nb += 3;
if (func && funclen) {
buf[nb++] = ' ';
if (funclen > sizeof(buf) - nb - 1)
if ((size_t)funclen > sizeof(buf) - nb - 1)
funclen = sizeof(buf) - nb - 1;
memcpy(buf + nb, func, funclen);
nb += funclen;
Expand Down Expand Up @@ -437,7 +437,7 @@ void* xdl_alloc_grow_helper(void *p, long nr, long *alloc, size_t size)
{
void *tmp = NULL;
size_t n = ((LONG_MAX - 16) / 2 >= *alloc) ? 2 * *alloc + 16 : LONG_MAX;
if (nr > n)
if ((size_t)nr > n)
n = nr;
if (SIZE_MAX / size >= n)
tmp = xdl_realloc(p, n * size);
Expand Down

0 comments on commit 8ff1fb3

Please sign in to comment.