diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-02-03 03:34:40 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-02-03 03:34:40 +0100 |
commit | 982c44d030dbb9eec3ae6522b12838c5f0754070 (patch) | |
tree | 2c2a2bb0b9d2a3f4f01bd10f0096ecb21a209e8a | |
parent | 83dd4ff69631f8def367920b3353e112b93fcc87 (diff) | |
download | busybox-982c44d030dbb9eec3ae6522b12838c5f0754070.tar.gz |
bzip2: rewrite bit of code which depends on integer overflow
function old new delta
sendMTFValues 2093 2070 -23
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/libarchive/bz/compress.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/archival/libarchive/bz/compress.c b/archival/libarchive/bz/compress.c index 377f2f166..271982cf2 100644 --- a/archival/libarchive/bz/compress.c +++ b/archival/libarchive/bz/compress.c @@ -297,7 +297,7 @@ void sendMTFValues(EState* s) // 200..599 = 3 // 600..1199 = 4 // 1200..2399 = 5 - // else 6 + // 2400..99999 = 6 nGroups = 2; nGroups += (s->nMTF >= 200); nGroups += (s->nMTF >= 600); @@ -317,12 +317,12 @@ void sendMTFValues(EState* s) unsigned tFreq, aFreq; tFreq = remF / nPart; - ge = gs - 1; //underflows on 1st iteration + ge = gs; aFreq = 0; - while (aFreq < tFreq && (int)ge < (int)alphaSize-1) { - ge++; - aFreq += s->mtfFreq[ge]; + while (aFreq < tFreq && ge < alphaSize) { + aFreq += s->mtfFreq[ge++]; } + ge--; if (ge > gs && nPart != nGroups && nPart != 1 |