Skip to content

Commit 8ff1fb3

Browse files
committed
Merge branch 'da/xdiff-w-sign-compare-workaround' into seen
* 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
2 parents a4b649a + a3b56f5 commit 8ff1fb3

File tree

6 files changed

+10
-12
lines changed

6 files changed

+10
-12
lines changed

xdiff/xdiffi.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
* Davide Libenzi <[email protected]>
2020
*
2121
*/
22-
#define DISABLE_SIGN_COMPARE_WARNINGS
2322

2423
#include "xinclude.h"
2524

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

10151014
static int record_matches_regex(xrecord_t *rec, xpparam_t const *xpp) {
10161015
regmatch_t regmatch;
1017-
int i;
1016+
size_t i;
10181017

10191018
for (i = 0; i < xpp->ignore_regex_nr; i++)
10201019
if (!regexec_buf(xpp->ignore_regex[i], rec->ptr, rec->size, 1,

xdiff/xemit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ xdchange_t *xdl_get_hunk(xdchange_t **xscr, xdemitconf_t const *xecfg)
5454
xdchange_t *xch, *xchp, *lxch;
5555
long max_common = 2 * xecfg->ctxlen + xecfg->interhunkctxlen;
5656
long max_ignorable = xecfg->ctxlen;
57-
unsigned long ignored = 0; /* number of ignored blank lines */
57+
long ignored = 0; /* number of ignored blank lines */
5858

5959
/* remove ignorable changes that are too far before other changes */
6060
for (xchp = *xscr; xchp && xchp->ignore; xchp = xchp->next) {

xdiff/xhistogram.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static int scanA(struct histindex *index, int line1, int count1)
106106
unsigned int chain_len;
107107
struct record **rec_chain, *rec;
108108

109-
for (ptr = LINE_END(1); line1 <= ptr; ptr--) {
109+
for (ptr = LINE_END(1); (unsigned int)line1 <= ptr; ptr--) {
110110
tbl_idx = TABLE_HASH(index, 1, ptr);
111111
rec_chain = index->records + tbl_idx;
112112
rec = *rec_chain;
@@ -181,14 +181,14 @@ static int try_lcs(struct histindex *index, struct region *lcs, int b_ptr,
181181
be = bs;
182182
rc = rec->cnt;
183183

184-
while (line1 < as && line2 < bs
184+
while ((unsigned int)line1 < as && (unsigned int)line2 < bs
185185
&& CMP(index, 1, as - 1, 2, bs - 1)) {
186186
as--;
187187
bs--;
188188
if (1 < rc)
189189
rc = XDL_MIN(rc, CNT(index, as));
190190
}
191-
while (ae < LINE_END(1) && be < LINE_END(2)
191+
while (ae < (unsigned int)LINE_END(1) && be < (unsigned int)LINE_END(2)
192192
&& CMP(index, 1, ae + 1, 2, be + 1)) {
193193
ae++;
194194
be++;
@@ -313,7 +313,7 @@ static int histogram_diff(xpparam_t const *xpp, xdfenv_t *env,
313313
if (count1 <= 0 && count2 <= 0)
314314
return 0;
315315

316-
if (LINE_END(1) >= MAX_PTR)
316+
if ((unsigned int)LINE_END(1) >= MAX_PTR)
317317
return -1;
318318

319319
if (!count1) {

xdiff/xinclude.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#if !defined(XINCLUDE_H)
2424
#define XINCLUDE_H
2525

26-
#define DISABLE_SIGN_COMPARE_WARNINGS
27-
2826
#include "git-compat-util.h"
2927
#include "xmacros.h"
3028
#include "xdiff.h"

xdiff/xpatience.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* Davide Libenzi <[email protected]>
2020
*
2121
*/
22+
2223
#include "xinclude.h"
2324

2425
/*
@@ -75,7 +76,7 @@ struct hashmap {
7576

7677
static int is_anchor(xpparam_t const *xpp, const char *line)
7778
{
78-
int i;
79+
size_t i;
7980
for (i = 0; i < xpp->anchors_nr; i++) {
8081
if (!strncmp(line, xpp->anchors[i], strlen(xpp->anchors[i])))
8182
return 1;

xdiff/xutils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ static int xdl_format_hunk_hdr(long s1, long c1, long s2, long c2,
375375
nb += 3;
376376
if (func && funclen) {
377377
buf[nb++] = ' ';
378-
if (funclen > sizeof(buf) - nb - 1)
378+
if ((size_t)funclen > sizeof(buf) - nb - 1)
379379
funclen = sizeof(buf) - nb - 1;
380380
memcpy(buf + nb, func, funclen);
381381
nb += funclen;
@@ -437,7 +437,7 @@ void* xdl_alloc_grow_helper(void *p, long nr, long *alloc, size_t size)
437437
{
438438
void *tmp = NULL;
439439
size_t n = ((LONG_MAX - 16) / 2 >= *alloc) ? 2 * *alloc + 16 : LONG_MAX;
440-
if (nr > n)
440+
if ((size_t)nr > n)
441441
n = nr;
442442
if (SIZE_MAX / size >= n)
443443
tmp = xdl_realloc(p, n * size);

0 commit comments

Comments
 (0)