diff options
author | Jack Palevich <jackpal@google.com> | 2009-10-28 19:38:05 -0700 |
---|---|---|
committer | Jack Palevich <jackpal@google.com> | 2009-10-28 19:38:05 -0700 |
commit | 4a943184544159a57ca749af53bab0f1a98435a1 (patch) | |
tree | a72f93480890619c6094c70ef8cafb4e397bdba8 /core/jni | |
parent | 31957f1badbb900bbfe211317e1ea992d650a72d (diff) | |
download | frameworks_base-4a943184544159a57ca749af53bab0f1a98435a1.zip frameworks_base-4a943184544159a57ca749af53bab0f1a98435a1.tar.gz frameworks_base-4a943184544159a57ca749af53bab0f1a98435a1.tar.bz2 |
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.
Diffstat (limited to 'core/jni')
-rw-r--r-- | core/jni/android_text_format_Time.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/core/jni/android_text_format_Time.cpp b/core/jni/android_text_format_Time.cpp index 98f4e03..fde6ca6 100644 --- a/core/jni/android_text_format_Time.cpp +++ b/core/jni/android_text_format_Time.cpp @@ -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 { - char msg[100]; - sprintf(msg, "Parse error at pos=%d", spos); - jniThrowException(env, "android/util/TimeFormatException", msg); - *thrown = true; + if (!*thrown) { + char msg[100]; + sprintf(msg, "Parse error at pos=%d", spos); + jniThrowException(env, "android/util/TimeFormatException", msg); + *thrown = true; + } return 0; } } |