Skip to content

Commit 0ed49a3

Browse files
fiberbitJunio C Hamano
authored andcommitted
xdiff/xdiffi.c: fix warnings about possibly uninitialized variables
Compiling this module gave the following warnings (some double dutch!): xdiff/xdiffi.c: In functie 'xdl_recs_cmp': xdiff/xdiffi.c:298: let op: 'spl.i1' may be used uninitialized in this function xdiff/xdiffi.c:298: let op: 'spl.i2' may be used uninitialized in this function xdiff/xdiffi.c:219: let op: 'fbest1' may be used uninitialized in this function xdiff/xdiffi.c:219: let op: 'bbest1' may be used uninitialized in this function A superficial tracking of their usage, without deeper knowledge about the algorithm, indeed confirms that there are code paths on which these variables will be used uninitialized. In practice these code paths might never be reached, but then these fixes will not change the algorithm. If these code paths are ever reached we now at least have a predictable outcome. And should the very small performance impact of these initializations be noticeable, then they should at least be replaced by comments why certain code paths will never be reached. Some extra initializations in this patch now fix the warnings.
1 parent fc58071 commit 0ed49a3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

xdiff/xdiffi.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
218218
if (ec >= xenv->mxcost) {
219219
long fbest, fbest1, bbest, bbest1;
220220

221-
fbest = -1;
221+
fbest = fbest1 = -1;
222222
for (d = fmax; d >= fmin; d -= 2) {
223223
i1 = XDL_MIN(kvdf[d], lim1);
224224
i2 = i1 - d;
@@ -230,7 +230,7 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
230230
}
231231
}
232232

233-
bbest = XDL_LINE_MAX;
233+
bbest = bbest1 = XDL_LINE_MAX;
234234
for (d = bmax; d >= bmin; d -= 2) {
235235
i1 = XDL_MAX(off1, kvdb[d]);
236236
i2 = i1 - d;
@@ -296,6 +296,7 @@ int xdl_recs_cmp(diffdata_t *dd1, long off1, long lim1,
296296
} else {
297297
long ec;
298298
xdpsplit_t spl;
299+
spl.i1 = spl.i2 = 0;
299300

300301
/*
301302
* Divide ...

0 commit comments

Comments
 (0)