git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH JGIT] Computation of average could overflow

From
Shawn O. Pearce <spearce@spearce.org>
Date
Apr 27, 2009, 23:17 UTC
Message-ID
<20090427231757.GM23604@spearce.org>
In-Reply-To
<366BBB1215D0AB4B8A153AF047A2878002FCE7E7@dewdfe18.wdf.sap.corp>
"Sohn, Matthias" <matthias.sohn@sap.com> wrote:
Show 7 quoted lines
> 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.
Previous: Shawn O. Pearce
Message 9 of 9 in “Computation of average could overflow”
  1. Computation of average could overflowSohn, Matthias, Apr 27, 2009
  2. Method invokes inefficient new String(String) constructorSohn, Matthias, Apr 27, 2009
  3. Method invokes inefficient Number constructor; use static valueOf insteadSohn, Matthias, Apr 27, 2009
  4. Method ignores results of InputStream.skip()Sohn, Matthias, Apr 27, 2009
  5. Shawn O. PearceApr 27, 2009
  6. Method ignores results of InputStream.skip()Sohn, Matthias, Apr 28, 2009
  7. Shawn O. PearceApr 27, 2009
  8. Shawn O. PearceApr 27, 2009
  9. Shawn O. PearceApr 27, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.