title: glGetFloatv causes stack smash
body: <p>This causes a stack smash when compiled with GCC.</p>
  
  <pre><code>void MyOpenGLLineClass::set_width (float x)
  {
      float max = 1;
  
      glGetFloatv (GL_ALIASED_LINE_WIDTH_RANGE, &amp;max);
  
      if (false == (x &gt; 0 &amp;&amp; x &lt;= max))
          throw std::invalid_argument (__PRETTY_FUNCTION__);
  
      m_width = x;
  }
  </code></pre>
  
  <p>It happens in a program which otherwise behaves as expected. If I comment-out the <code>glGetFloatv</code> the stack smash goes away.</p>
  
  <p>Here is the machine code:</p>
  
  <pre><code>   0x00005555556503be &lt;+0&gt;:     push   %rbp
     0x00005555556503bf &lt;+1&gt;:     mov    %rsp,%rbp
     0x00005555556503c2 &lt;+4&gt;:     push   %r12
     0x00005555556503c4 &lt;+6&gt;:     push   %rbx
     0x00005555556503c5 &lt;+7&gt;:     sub    $0x20,%rsp
     0x00005555556503c9 &lt;+11&gt;:    callq  *0x2e2bf9(%rip)        # 0x555555932fc8
     0x00005555556503cf &lt;+17&gt;:    mov    %rdi,-0x28(%rbp)
     0x00005555556503d3 &lt;+21&gt;:    movss  %xmm0,-0x2c(%rbp)
     0x00005555556503d8 &lt;+26&gt;:    mov    %fs:0x28,%rax
     0x00005555556503e1 &lt;+35&gt;:    mov    %rax,-0x18(%rbp)
     0x00005555556503e5 &lt;+39&gt;:    xor    %eax,%eax
     0x00005555556503e7 &lt;+41&gt;:    pxor   %xmm0,%xmm0
     0x00005555556503eb &lt;+45&gt;:    movss  %xmm0,-0x1c(%rbp)
     0x00005555556503f0 &lt;+50&gt;:    lea    -0x1c(%rbp),%rax
     0x00005555556503f4 &lt;+54&gt;:    mov    %rax,%rsi
     0x00005555556503f7 &lt;+57&gt;:    mov    $0x846e,%edi
     0x00005555556503fc &lt;+62&gt;:    callq  0x5555556262d0 &lt;glGetFloatv@plt&gt;
     0x0000555555650401 &lt;+67&gt;:    movss  -0x2c(%rbp),%xmm0
     0x0000555555650406 &lt;+72&gt;:    pxor   %xmm1,%xmm1
     0x000055555565040a &lt;+76&gt;:    comiss %xmm1,%xmm0
     0x000055555565040d &lt;+79&gt;:    seta   %al
     0x0000555555650410 &lt;+82&gt;:    xor    $0x1,%eax
     0x0000555555650413 &lt;+85&gt;:    test   %al,%al
     0x0000555555650415 &lt;+87&gt;:    jne    0x55555565042a &lt;MyOpenGLLineClass::set_width(float)+108&gt;
     0x0000555555650417 &lt;+89&gt;:    movss  -0x1c(%rbp),%xmm0
     0x000055555565041c &lt;+94&gt;:    comiss -0x2c(%rbp),%xmm0
     0x0000555555650420 &lt;+98&gt;:    setae  %al
     0x0000555555650423 &lt;+101&gt;:   xor    $0x1,%eax
     0x0000555555650426 &lt;+104&gt;:   test   %al,%al
     0x0000555555650428 &lt;+106&gt;:   je     0x55555565045f &lt;MyOpenGLLineClass::set_width(float)+161&gt;
     0x000055555565042a &lt;+108&gt;:   mov    $0x10,%edi
     0x000055555565042f &lt;+113&gt;:   callq  0x555555626130 &lt;__cxa_allocate_exception@plt&gt;
     0x0000555555650434 &lt;+118&gt;:   mov    %rax,%rbx
     0x0000555555650437 &lt;+121&gt;:   lea    0x8ee42(%rip),%rsi        # 0x5555556df280 &lt;_ZZN3CMyOpenGLLineClass9set_widthEfE19__PRETTY_FUNCTION__&gt;
     0x000055555565043e &lt;+128&gt;:   mov    %rbx,%rdi
     0x0000555555650441 &lt;+131&gt;:   callq  0x555555625f80 &lt;_ZNSt16invalid_argumentC1EPKc@plt&gt;
     0x0000555555650446 &lt;+136&gt;:   mov    0x2e2b5b(%rip),%rax        # 0x555555932fa8
     0x000055555565044d &lt;+143&gt;:   mov    %rax,%rdx
     0x0000555555650450 &lt;+146&gt;:   lea    0x2de9f1(%rip),%rsi        # 0x55555592ee48 &lt;_ZTISt16invalid_argument@@GLIBCXX_3.4&gt;
     0x0000555555650457 &lt;+153&gt;:   mov    %rbx,%rdi
     0x000055555565045a &lt;+156&gt;:   callq  0x555555625a80 &lt;__cxa_throw@plt&gt;
     0x000055555565045f &lt;+161&gt;:   mov    -0x28(%rbp),%rax
     0x0000555555650463 &lt;+165&gt;:   movss  -0x2c(%rbp),%xmm0
     0x0000555555650468 &lt;+170&gt;:   movss  %xmm0,0x58(%rax)
     0x000055555565046d &lt;+175&gt;:   nop
     0x000055555565046e &lt;+176&gt;:   mov    -0x18(%rbp),%rax
     0x0000555555650472 &lt;+180&gt;:   xor    %fs:0x28,%rax
     0x000055555565047b &lt;+189&gt;:   je     0x55555565049a &lt;MyOpenGLLineClass::set_width(float)+220&gt;
     0x000055555565047d &lt;+191&gt;:   jmp    0x555555650495 &lt;MyOpenGLLineClass::set_width(float)+215&gt;
     0x000055555565047f &lt;+193&gt;:   mov    %rax,%r12
     0x0000555555650482 &lt;+196&gt;:   mov    %rbx,%rdi
     0x0000555555650485 &lt;+199&gt;:   callq  0x5555556263c0 &lt;__cxa_free_exception@plt&gt;
     0x000055555565048a &lt;+204&gt;:   mov    %r12,%rax
     0x000055555565048d &lt;+207&gt;:   mov    %rax,%rdi
     0x0000555555650490 &lt;+210&gt;:   callq  0x555555625b00 &lt;_Unwind_Resume@plt&gt;
     0x0000555555650495 &lt;+215&gt;:   callq  0x5555556258a0 &lt;__stack_chk_fail@plt&gt;
  =&gt; 0x000055555565049a &lt;+220&gt;:   add    $0x20,%rsp
     0x000055555565049e &lt;+224&gt;:   pop    %rbx
     0x000055555565049f &lt;+225&gt;:   pop    %r12
     0x00005555556504a1 &lt;+227&gt;:   pop    %rbp
     0x00005555556504a2 &lt;+228&gt;:   retq
  </code></pre>
  
  <p>Why is this stack smash happening?</p>