diff --git a/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java b/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java index bb01eb4ac..b2ad87e09 100644 --- a/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java +++ b/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java @@ -999,13 +999,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { int dd; } - private void qSort3(int loSt, int hiSt, int dSt) { + private void qSort3(int loSt, int hiSt, int dSt, StackElem[] stack) { int unLo, unHi, ltLo, gtHi, med, n, m; int sp, lo, hi, d; - StackElem[] stack = new StackElem[QSORT_STACK_SIZE]; - for (int count = 0; count < QSORT_STACK_SIZE; count++) { - stack[count] = new StackElem(); - } sp = 0; @@ -1228,6 +1224,11 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { } while (h != 1); } + StackElem[] stack = new StackElem[QSORT_STACK_SIZE]; + for (int count = 0; count < QSORT_STACK_SIZE; count++) { + stack[count] = new StackElem(); + } + /* The main sorting loop. */ @@ -1251,7 +1252,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { int lo = ftab[sb] & CLEARMASK; int hi = (ftab[sb + 1] & CLEARMASK) - 1; if (hi > lo) { - qSort3(lo, hi, 2); + qSort3(lo, hi, 2, stack); numQSorted += (hi - lo + 1); if (workDone > workLimit && firstAttempt) { return;