OSDN Git Service

Fix a use-of-uninitialized-value warning
authorGeorge Burgess IV <gbiv@google.com>
Wed, 1 Feb 2017 00:21:25 +0000 (16:21 -0800)
committerGeorge Burgess IV <gbiv@google.com>
Wed, 1 Feb 2017 00:21:25 +0000 (16:21 -0800)
Caught by clang's static analyzer:
frameworks/base/core/jni/com_google_android_gles_jni_GLImpl.cpp:190:30:
warning: The right operand of '+' is a garbage value
            buf = (char*)buf + offset;

This is because getPointer doesn't always set `offset` to a value. We
could fix it locally by initializing `offset`, but it seems to be less
error-prone to just fix getPointer instead.

Bug: None
Test: Still builds; warning is now gone.
Change-Id: I90bea0c94cf8d7f92a0d9a4db4e64e7e563bfb09

opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp

index f5506ba..026cb37 100644 (file)
@@ -131,6 +131,7 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o
     pointer = _env->CallStaticLongMethod(nioAccessClass,
             getBasePointerID, buffer);
     if (pointer != 0L) {
+        *offset = 0;
         *array = NULL;
         return reinterpret_cast<void *>(pointer);
     }
@@ -138,6 +139,7 @@ getPointer(JNIEnv *_env, jobject buffer, jarray *array, jint *remaining, jint *o
     *array = (jarray) _env->CallStaticObjectMethod(nioAccessClass,
             getBaseArrayID, buffer);
     if (*array == NULL) {
+        *offset = 0;
         return (void*) NULL;
     }
     *offset = _env->CallStaticIntMethod(nioAccessClass,