Skip to content

Commit

Permalink
Fix integer overflow when computing alignment interval centers for la…
Browse files Browse the repository at this point in the history
…rge chromosomes. Fixes #977
  • Loading branch information
jrobinso committed Jun 5, 2021
1 parent 4658a36 commit 6459c1e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/broad/igv/sam/AlignmentDataManager.java
Expand Up @@ -354,8 +354,8 @@ public void load(ReferenceFrame frame,

// Expand the interval by the lesser of +/- a 2 screens, or max visible range
int windowSize = Math.min(4 * (end - start), PreferencesManager.getPreferences().getAsInt(SAM_MAX_VISIBLE_RANGE) * 1000);
int center = (end + start) / 2;
int expand = Math.max(end - start, windowSize / 2);
int center = start + (end - start) / 2; // Be careful how you calculate this -- potential overflow for large chromosomes
int expand = Math.min(Integer.MAX_VALUE - center, Math.max(end - start, windowSize / 2));

if (expandEnds) {
adjustedStart = Math.max(0, Math.min(start, center - expand));
Expand Down

0 comments on commit 6459c1e

Please sign in to comment.