title: Android NDK jshortArray not as long as advertised
body: <p>I'm getting a segfault with the following code:</p>
  
  <pre><code>#include &lt;stddef.h&gt;
  #include &lt;android/log.h&gt;
  #include "com_backyardbrains_drawing_BybGLDrawable.h"
  
  #define ALOG(msg) __android_log_print(ANDROID_LOG_DEBUG, "NDK:BYB", msg)
  #define AERR(msg) __android_log_print(ANDROID_LOG_ERROR, "NDK:BYB", msg)
  
  JNIEXPORT jfloatArray JNICALL
  Java_com_backyardbrains_drawing_BybGLDrawable_interleaveXvalues
  (JNIEnv *env, jclass clazz, jshortArray shortArrayToDraw) {
  ALOG("called interleave");
  
      jfloatArray result;
      jsize len = (*env)-&gt;GetArrayLength(env, shortArrayToDraw);
      __android_log_print(ANDROID_LOG_DEBUG, "NDK:BYB",
                         "Got input length of %d", len);
      jshort *valuesjs = (*env)-&gt;GetShortArrayElements(env, shortArrayToDraw, NULL);
      if (valuesjs == NULL || !(len &gt; 0)) {
          return NULL;
      }
      jfloat tmp[len*2];
      __android_log_print(ANDROID_LOG_DEBUG, "NDK:BYB",
                    "made a new tmp array of size %d",
                    sizeof(tmp)/sizeof(jfloat));
      // Create the returnable 2D array
      result = (*env)-&gt;NewFloatArray(env, len*2);
      if (result == NULL) {
          AERR("could not allocate result");
          return NULL;
      }
  
      int i;
      for (i = 0; i &lt; len; i++) {
          tmp[i*2] = i;
          tmp[i*2+1] = valuesjs[i];
          __android_log_print(ANDROID_LOG_DEBUG, "NDK:BYB", "Set element %d", i);
      }
      ALOG("Finished building new array");
  
      (*env)-&gt;ReleaseShortArrayElements(env, shortArrayToDraw, valuesjs, 0);
      ALOG("released old short array");
  
      (*env)-&gt;SetFloatArrayRegion(env, result, 0, len*2, tmp);
      ALOG("set new float array");
      return result;
  
  }
  </code></pre>
  
  <p>The log output goes something like:</p>
  
  <pre><code>06-19 21:34:24.829 29156 29172 D NDK:BYB : called interleave
  06-19 21:34:24.829 29156 29172 D NDK:BYB : Got input length of 131072
  06-19 21:34:24.829 29156 29172 D NDK:BYB : made a new tmp array of size 262144            
  06-19 21:34:25.157 29156 29172 D NDK:BYB : Set element 0
  ... 
  06-19 21:34:25.157 29156 29172 D NDK:BYB : Set element 158
  06-19 21:34:25.367 29204 29204 I DEBUG   : pid: 29156, tid: 29172  &gt;&gt;&gt; com.backyardbrains &lt;&lt;&lt;
  06-19 21:34:25.367 29204 29204 I DEBUG   : signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 450ac000
  </code></pre>
  
  <p>The problem occurs consistently at value <code>159</code> for <code>i</code> for the <code>for</code> loop. However, the expected length of the array getting passed in to this function is a fixed 131072 elements (as reflected in the log). Why are values farther down the array inaccessible?</p>