* [PATCH] xdiff/xdiffi.c: fix warnings about possibly uninitialized variables
@ 2006-04-08 15:27 Marco Roeland
2006-04-08 17:18 ` Davide Libenzi
0 siblings, 1 reply; 2+ messages in thread
From: Marco Roeland @ 2006-04-08 15:27 UTC (permalink / raw)
To: git; +Cc: Davide Libenzi
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.
---
xdiff/xdiffi.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
0b0bf00d67a66b3ef47862cc51b1d37763f4b99b
diff --git a/xdiff/xdiffi.c b/xdiff/xdiffi.c
index e81bca6..641362d 100644
--- a/xdiff/xdiffi.c
+++ b/xdiff/xdiffi.c
@@ -218,7 +218,7 @@ static long xdl_split(unsigned long cons
if (ec >= xenv->mxcost) {
long fbest, fbest1, bbest, bbest1;
- fbest = -1;
+ fbest = fbest1 = -1;
for (d = fmax; d >= fmin; d -= 2) {
i1 = XDL_MIN(kvdf[d], lim1);
i2 = i1 - d;
@@ -230,7 +230,7 @@ static long xdl_split(unsigned long cons
}
}
- bbest = XDL_LINE_MAX;
+ bbest = bbest1 = XDL_LINE_MAX;
for (d = bmax; d >= bmin; d -= 2) {
i1 = XDL_MAX(off1, kvdb[d]);
i2 = i1 - d;
@@ -296,6 +296,7 @@ int xdl_recs_cmp(diffdata_t *dd1, long o
} else {
long ec;
xdpsplit_t spl;
+ spl.i1 = spl.i2 = 0;
/*
* Divide ...
--
1.3.0.rc3.gad0b
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] xdiff/xdiffi.c: fix warnings about possibly uninitialized variables
2006-04-08 15:27 [PATCH] xdiff/xdiffi.c: fix warnings about possibly uninitialized variables Marco Roeland
@ 2006-04-08 17:18 ` Davide Libenzi
0 siblings, 0 replies; 2+ messages in thread
From: Davide Libenzi @ 2006-04-08 17:18 UTC (permalink / raw)
To: Marco Roeland; +Cc: git
On Sat, 8 Apr 2006, Marco Roeland wrote:
> 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.
These paths are never reached because of the way data is prepared before
and passed to the function. Unfortunately the compiler cannot know this.
Using them as -1 or XDL_LINE_MAX won't help either, since those are out of
domain values. You can leave it there and the algo won't suffer, or you
can relax a little the warning level when building the file.
- Davide
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-04-08 17:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-08 15:27 [PATCH] xdiff/xdiffi.c: fix warnings about possibly uninitialized variables Marco Roeland
2006-04-08 17:18 ` Davide Libenzi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox