diff -Naur lbzip2-2.2_orig/src/encode.c lbzip2-2.2/src/encode.c --- lbzip2-2.2_orig/src/encode.c 2012-08-06 02:34:24.000000000 +0200 +++ lbzip2-2.2/src/encode.c 2012-09-27 16:36:37.788182811 +0200 @@ -789,8 +789,12 @@ for (a = 0, t = 0; t < nt; t++) { /* Find a range of symbols which total count is roughly proportional to one nt-th of all values. */ - for (c = 0, b = a; c * (nt-t) < nm; b++) + c = 0, b = a; + do { c += s->lookup[0][b]; + b++; + } while (c * (nt-t) < nm); + assert(a < b); if (a < b-1 && (2*c - s->lookup[0][b-1]) * (nt-t) > 2*nm) { c -= s->lookup[0][--b];