From: mlichvar Date: Thu, 12 Oct 2006 13:48:07 +0000 (+0000) Subject: - handle large values correctly X-Git-Tag: r0-52-4~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3db22aa23c519978c6d476f0215c40f8337d8f7;p=thirdparty%2Fnewt.git - handle large values correctly --- diff --git a/scale.c b/scale.c index f898916..2667af0 100644 --- a/scale.c +++ b/scale.c @@ -48,11 +48,17 @@ void newtScaleSet(newtComponent co, unsigned long long amount) { struct scale * sc = co->data; int newPercentage; - sc->charsSet = (amount * co->width) / sc->fullValue; - newPercentage = (amount * 100) / sc->fullValue; - - if (newPercentage > 100) + if (amount >= sc->fullValue) { newPercentage = 100; + sc->charsSet = co->width; + } else if (sc->fullValue >= -1ULL / (100 > co->width ? 100 : co->width)) { + /* avoid overflow on large numbers */ + sc->charsSet = amount / (sc->fullValue / co->width); + newPercentage = amount / (sc->fullValue / 100); + } else { + sc->charsSet = (amount * co->width) / sc->fullValue; + newPercentage = (amount * 100) / sc->fullValue; + } if (newPercentage != sc->percentage) { sc->percentage = newPercentage;