diff options
| author | 2014-01-16 13:17:03 +0000 | |
|---|---|---|
| committer | 2014-01-16 13:18:28 +0000 | |
| commit | 6ffb09171960e776466b963e51196565a033998c (patch) | |
| tree | e7787c889ec33e406fe7efabf835d92361e6d8af | |
| parent | 486544f763bd27eb92c95101e23f939c79c9890e (diff) | |
Fix error checking in MemoryFile.
mmap returns MAP_FAILED on failures, not 0 (NULL).
Also, convert some C style casts to C++ since they
make intent clearer.
Change-Id: I367993c73e9ee576f11ebe76e530d2c2f27c662d
| -rw-r--r-- | core/jni/android_os_MemoryFile.cpp | 9 | 
1 files changed, 5 insertions, 4 deletions
diff --git a/core/jni/android_os_MemoryFile.cpp b/core/jni/android_os_MemoryFile.cpp index 88a3738de587..27b29bc11930 100644 --- a/core/jni/android_os_MemoryFile.cpp +++ b/core/jni/android_os_MemoryFile.cpp @@ -47,15 +47,16 @@ static jlong android_os_MemoryFile_mmap(JNIEnv* env, jobject clazz, jobject file          jint length, jint prot)  {      int fd = jniGetFDFromFileDescriptor(env, fileDescriptor); -    jlong result = (jlong)mmap(NULL, length, prot, MAP_SHARED, fd, 0); -    if (!result) +    void* result = mmap(NULL, length, prot, MAP_SHARED, fd, 0); +    if (result == MAP_FAILED) {          jniThrowException(env, "java/io/IOException", "mmap failed"); -    return result; +    } +    return reinterpret_cast<jlong>(result);  }  static void android_os_MemoryFile_munmap(JNIEnv* env, jobject clazz, jlong addr, jint length)  { -    int result = munmap((void *)addr, length); +    int result = munmap(reinterpret_cast<void *>(addr), length);      if (result < 0)          jniThrowException(env, "java/io/IOException", "munmap failed");  }  |