From: Shawn O. Pearce Date: Mon, 27 Apr 2009 23:17:57 GMT Subject: Re: [PATCH JGIT] Computation of average could overflow Message-ID: <20090427231757.GM23604@spearce.org> In-Reply-To: <366BBB1215D0AB4B8A153AF047A2878002FCE7E7@dewdfe18.wdf.sap.corp> "Sohn, Matthias" wrote: > The code computes the average of two integers using either division or > signed right shift, and then uses the result as the > index of an array. If the values being averaged are very large, this can > overflow (resulting in the computation of a negative > average). Assuming that the result is intended to be nonnegative, you > can use an unsigned right shift instead. In other > words, rather that using (low+high)/2, use (low+high) >>> 1 Thanks, applied. But your patch was line wrapped. I had to unwrap it by hand. Please try to configure your MUA not to line wrap patches when it sends them. :-| > .../src/org/spearce/jgit/dircache/DirCache.java | 2 +- > .../src/org/spearce/jgit/lib/Tree.java | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) -- Shawn.