Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 64751001 authored by Hans Boehm's avatar Hans Boehm
Browse files

Deal with small displays and a cancellation race

Bug: 34824406
Bug: 34949414

Check for unreasonably small display sizes and avoid crashing.

Incomplete fix for a cancellation race in which we write the expression
value back after the evaluation has been cancelled, and possibly
replaced.

Test: Some experiments with manually setting maxChars in redisplay().
Normal unit tests.

Change-Id: I7e11043eb5999bf373d66cc827de83024ef217f0
parent 615b4119
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -745,6 +745,10 @@ public class CalculatorResult extends AlignedTextView implements MenuItem.OnMenu
                        ++exponent;
                    }
                }
                if (dropDigits >= result.length() - 1) {
                    // Display too small to show meaningful result.
                    return KeyMaps.ELLIPSIS + "E" + KeyMaps.ELLIPSIS;
                }
                result = result.substring(0, result.length() - dropDigits);
                if (lastDisplayedOffset != null) {
                    lastDisplayedOffset[0] -= dropDigits;
@@ -919,11 +923,15 @@ public class CalculatorResult extends AlignedTextView implements MenuItem.OnMenu
    }

    public void redisplay() {
        int maxChars = getMaxChars();
        if (maxChars < 4) {
            // Display currently too small to display a reasonable result. Punt to avoid crash.
            return;
        }
        if (mScroller.isFinished() && length() > 0) {
            setAccessibilityLiveRegion(ACCESSIBILITY_LIVE_REGION_POLITE);
        }
        int currentCharOffset = getCharOffset(mCurrentPos);
        int maxChars = getMaxChars();
        int lastDisplayedOffset[] = new int[1];
        String result = getFormattedResult(currentCharOffset, maxChars, lastDisplayedOffset,
                mAppendExponent /* forcePrecision; preserve entire result */,
+4 −0
Original line number Diff line number Diff line
@@ -574,6 +574,10 @@ public class Evaluator implements CalculatorExpr.ExprResolver {
                if (res == null) {
                    try {
                        res = mExprInfo.mExpr.eval(mDm, Evaluator.this);
                        if (isCancelled()) {
                            // TODO: This remains very slightly racey. Fix this.
                            throw new CR.AbortedException();
                        }
                        res = putResultIfAbsent(mIndex, res);
                    } catch (StackOverflowError e) {
                        // Absurdly large integer exponents can cause this. There might be other