title: Why are the parameters to my C++ function filled with garbage?
body: <p>I am currently attempting to write a small program in C++ to learn a specific feature of OpenGl (Transform feedback). I have a small function that is part of this program that is supposed to load a shader and provide a GLuint to the user of that function. </p>
  
  <p>Function in header:</p>
  
  <pre><code>namespace glutils{
  
     GLuint loadShader(const std::string &amp;path, GLenum type);
  
  }
  </code></pre>
  
  <p>Function implementation:</p>
  
  <pre><code>GLuint glutils::loadShader(const std::string &amp;path, GLenum type) {
      GLuint shader = glCreateShader(type);
  
      std::string shaderSource = utils::loadFile(path);
      const char *shaderSourceCString = shaderSource.c_str();
      glShaderSource(shader, 1, &amp;shaderSourceCString, nullptr);
  
      glCompileShader(shader);
  
      GLint success;
      glGetShaderiv(shader, GL_COMPILE_STATUS, &amp;success);
      if(!success){
          GLchar infoLog[1024];
          glGetShaderInfoLog(shader, 1024, nullptr, infoLog);
          throw std::runtime_error("Failed to compile shader " + path + ":\n" + infoLog);
      }
  
      return shader;
  }
  </code></pre>
  
  <p>Function use:</p>
  
  <pre><code>GLuint shader = glutils::loadShader("sqrt.glsl", GL_VERTEX_SHADER);
  </code></pre>
  
  <p>When I first ran my program, it was crashing with a segmentation fault. I used my debugger (LLDB wrapper in CLion) to determine where it is. It is the call to <code>glCreateShader</code> on the second line of my function. My debugger also told me that the parameter <code>path</code> is a string full of garbage, and that the parameter <code>type</code> contains a value different than that of <code>GL_VERTEX_SHADER</code>. When looking at the function, I noticed that I had initially forgotten to add a return to the end, which is undefined behavior and thus can cause this. Correcting this error, however, did not fix the garbage data arguments and associated segmentation fault. I tried searching for similar issues with my preferred search engine to no avail.</p>
  
  <p>What is the issue? How can I fix it?</p>