am bf31cb6b: am 8371f2e3: Merge "Check for OOM in BitmapFactory\'s getMimeTypeString()."

* commit 'bf31cb6be4290ce161d99a2a70c318f665a14a77':
  Check for OOM in BitmapFactory's getMimeTypeString().
This commit is contained in:
Vladimir Marko
2015-01-07 10:30:44 +00:00
committed by Android Git Automerger

View File

@@ -63,7 +63,7 @@ jstring getMimeTypeString(JNIEnv* env, SkImageDecoder::Format format) {
{ SkImageDecoder::kWBMP_Format, "image/vnd.wap.wbmp" } { SkImageDecoder::kWBMP_Format, "image/vnd.wap.wbmp" }
}; };
const char* cstr = NULL; const char* cstr = nullptr;
for (size_t i = 0; i < SK_ARRAY_COUNT(gMimeTypes); i++) { for (size_t i = 0; i < SK_ARRAY_COUNT(gMimeTypes); i++) {
if (gMimeTypes[i].fFormat == format) { if (gMimeTypes[i].fFormat == format) {
cstr = gMimeTypes[i].fMimeType; cstr = gMimeTypes[i].fMimeType;
@@ -71,8 +71,10 @@ jstring getMimeTypeString(JNIEnv* env, SkImageDecoder::Format format) {
} }
} }
jstring jstr = 0; jstring jstr = nullptr;
if (NULL != cstr) { if (cstr != nullptr) {
// NOTE: Caller should env->ExceptionCheck() for OOM
// (can't check for nullptr as it's a valid return value)
jstr = env->NewStringUTF(cstr); jstr = env->NewStringUTF(cstr);
} }
return jstr; return jstr;
@@ -324,10 +326,13 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding
// update options (if any) // update options (if any)
if (options != NULL) { if (options != NULL) {
jstring mimeType = getMimeTypeString(env, decoder->getFormat());
if (env->ExceptionCheck()) {
return nullObjectReturn("OOM in getMimeTypeString()");
}
env->SetIntField(options, gOptions_widthFieldID, scaledWidth); env->SetIntField(options, gOptions_widthFieldID, scaledWidth);
env->SetIntField(options, gOptions_heightFieldID, scaledHeight); env->SetIntField(options, gOptions_heightFieldID, scaledHeight);
env->SetObjectField(options, gOptions_mimeFieldID, env->SetObjectField(options, gOptions_mimeFieldID, mimeType);
getMimeTypeString(env, decoder->getFormat()));
} }
// if we're in justBounds mode, return now (skip the java bitmap) // if we're in justBounds mode, return now (skip the java bitmap)