title: Segfault when accessing char[]
body: <p>I've got a function</p>
  
  <pre><code>int foo() {
      ...
      char* real_path_buffer = (char*)malloc(sizeof(char)*PATH_MAX);
      realpath("a/certain/path/that/doesnt/exist", real_path_buffer);
      ...
  }
  </code></pre>
  
  <p>That makes a call to <code>realpath</code> in Android bionic</p>
  
  <pre><code>char* realpath(const __restrict char*, __restrict char*){
      char path1[PATH_MAX], path2[PATH_MAX], path3[PATH_MAX];
      ...
      path1 = something_valid; //recall, this is a library function
      ...
      memcpy(path2, path1, a_valid_size);
      ...
  }
  </code></pre>
  
  <p>And when passing a certain non-existent path to <code>realpath</code> from a production like scenario, I get a segfault upon accessing<code>path2</code> in any way (it happens when I simply try to print it as well as <code>memcpy</code> to it). </p>
  
  <p>I have verified that the program is not out of memory when the segfault occurs (by making a call to malloc and verifying that its return is not <code>NULL</code>) but you can be assured that this call happens on a fairly hefty stack. </p>
  
  <p>I've also verified that in less intense code paths, <code>realpath</code> accurately returns <code>NULL</code> without segfaulting.</p>
  
  <p>Does anyone have any ideas why this is happening? </p>