5834a31cf2b9000f0e268647d47f03f6944f9e9d angie Fri Feb 7 13:44:20 2020 -0800 Watch out for integer overflow for large gap penalties in gapCalcCost. refs #21650 diff --git src/lib/gapCalc.c src/lib/gapCalc.c index d811c1b..a1afd49 100644 --- src/lib/gapCalc.c +++ src/lib/gapCalc.c @@ -293,50 +293,59 @@ freeMem(gapCalc->bLong); freez(pGapCalc); } } int gapCalcCost(struct gapCalc *gapCalc, int dq, int dt) /* Figure out gap costs. */ { if (dt < 0) dt = 0; if (dq < 0) dq = 0; if (dt == 0) { if (dq < gapCalc->smallSize) return gapCalc->qSmall[dq]; else if (dq >= gapCalc->qLastPos) - return gapCalc->qLastPosVal + gapCalc->qLastSlope * (dq-gapCalc->qLastPos); + { + int cost = gapCalc->qLastPosVal + gapCalc->qLastSlope * (dq-gapCalc->qLastPos); + return (cost < 0) ? BIGNUM : cost; + } else return interpolate(dq, gapCalc->longPos, gapCalc->qLong, gapCalc->qPosCount); } else if (dq == 0) { if (dt < gapCalc->smallSize) return gapCalc->tSmall[dt]; else if (dt >= gapCalc->tLastPos) - return gapCalc->tLastPosVal + gapCalc->tLastSlope * (dt-gapCalc->tLastPos); + { + int cost = gapCalc->tLastPosVal + gapCalc->tLastSlope * (dt-gapCalc->tLastPos); + return (cost < 0) ? BIGNUM : cost; + } else return interpolate(dt, gapCalc->longPos, gapCalc->tLong, gapCalc->tPosCount); } else { int both = dq + dt; if (both < gapCalc->smallSize) return gapCalc->bSmall[both]; else if (both >= gapCalc->bLastPos) - return gapCalc->bLastPosVal + gapCalc->bLastSlope * (both-gapCalc->bLastPos); + { + int cost = gapCalc->bLastPosVal + gapCalc->bLastSlope * (both-gapCalc->bLastPos); + return (cost < 0) ? BIGNUM : cost; + } else return interpolate(both, gapCalc->longPos, gapCalc->bLong, gapCalc->bPosCount); } } void gapCalcTest(struct gapCalc *gapCalc) /* Print out gap cost info. */ { int i; for (i=1; i<=10; i++) { verbose(1, "%d: %d %d %d\n", i, gapCalcCost(gapCalc, i, 0), gapCalcCost(gapCalc, 0, i), gapCalcCost(gapCalc, i/2, i-i/2)); } for (i=1; ; i *= 10)