4fd52b1b34d170c15d3aacfeaf4fbb26fff224b1 hiram Wed Mar 25 12:52:00 2026 -0700 fix bugs for chrom size at 2^31 and manage partial computation windows at beginning or end of drawing window for gcOnFly refs #35958 diff --git src/hg/hgTracks/bigWigTrack.c src/hg/hgTracks/bigWigTrack.c index 1974f096599..7d8d4433704 100644 --- src/hg/hgTracks/bigWigTrack.c +++ src/hg/hgTracks/bigWigTrack.c @@ -411,35 +411,39 @@ } freeMem(windows); return pre; } static void gc5BaseOnTheFlyLoadItems(struct track *tg) /* Compute GC percent from genome sequence; called in the loadItems phase * just as bigWigLoadItems calls bigWigLoadPreDraw to fill preDrawContainer. * Fetch sequence that covers the preDraw smoothing margins on each side so * the smoothing/averaging machinery has data at the window edges. */ { tg->items = NULL; tg->mapsSelf = TRUE; /* Extend the fetch range by wiggleSmoothingMax pixels worth of bases on - * each side, rounded up to the nearest 5-base span. */ + * each side, rounded up to the nearest 5-base span. Use long long for + * the arithmetic to avoid 32-bit overflow near the ends of large chroms. */ double basesPerPixel = (double)(winEnd - winStart) / insideWidth; int marginBases = ((int)(wiggleSmoothingMax * basesPerPixel) / 5 + 1) * 5; -int fetchStart = max(0, winStart - marginBases); -int fetchEnd = min(hChromSize(database, chromName), winEnd + marginBases); +int chromSize = hChromSize(database, chromName); +long long fetchStartLong = (long long)winStart - marginBases; +int fetchStart = (fetchStartLong < 0) ? 0 : (int)fetchStartLong; +long long fetchEndLong = (long long)winEnd + marginBases; +int fetchEnd = (fetchEndLong > chromSize) ? chromSize : (int)fetchEndLong; gc5BaseOnTheFlyLoadPreDraw(tg, fetchStart, fetchEnd, insideWidth); } void bigWigMethods(struct track *track, struct trackDb *tdb, int wordCount, char *words[]) /* Set up bigWig methods. */ { bedGraphMethods(track, tdb, wordCount, words); track->loadItems = bigWigLoadItems; track->preDrawItems = bigWigPreDrawItems; track->preDrawMultiRegion = wigMultiRegionGraphLimits; track->drawItems = bigWigDrawItems; track->loadPreDraw = bigWigLoadPreDraw; }