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

Commit 4a943184 authored by Jack Palevich's avatar Jack Palevich
Browse files

Avoid trying to throw multiple exceptions at once.

The typical usage pattern for the get_char helper function is:

    bool thrown = false;

    n = get_char(env, s, 0, 1000, &thrown);
    n += get_char(env, s, 1, 100, &thrown);
    n += get_char(env, s, 2, 10, &thrown);
    n += get_char(env, s, 3, 1, &thrown);
    if (thrown) return false;

As you can see, get_char is called multiple times before the
thrown flag is checked. If the input text contains multiple
incorrect characters, then we have to guard against throwing
the same exception multiple times. (Because doing so will
cause the Dalvik runtime to abort.)

The fix is simple: modify get_char to check if an exception
has already been thrown before throwing a new exception.
parent 31957f1b
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -367,10 +367,12 @@ static int get_char(JNIEnv* env, const jchar *s, int spos, int mul,
    if (c >= '0' && c <= '9') {
        return (c - '0') * mul;
    } else {
        if (!*thrown) {
            char msg[100];
            sprintf(msg, "Parse error at pos=%d", spos);
            jniThrowException(env, "android/util/TimeFormatException", msg);
            *thrown = true;
        }
        return 0;
    }
}