title: zlib compress2 returning Z_STREAM_ERROR
body: <pre><code>char buffer[12] = {"Testing! 12"};
  
  unsigned long compressedSize;
  char* compressed = compress(buffer, 12, &amp;compressedSize);
  
  ...
  
  char* compress(char* buffer, unsigned long size, unsigned long* compressedSize)
  {
      Bytef* inBuffer = reinterpret_cast&lt;Bytef*&gt;(buffer);
      uLong inSize = static_cast&lt;uLong&gt;(size);
  
      Bytef* outBuffer = 0;
      uLong outBufferSize = compressBound(inSize);
  
      int error = compress2(outBuffer, &amp;outBufferSize, inBuffer, inSize, 6);
  
      if(error != Z_OK)
      {
          switch(error)
          {
              case Z_MEM_ERROR:
                  std::cerr &lt;&lt; "Memory error!" &lt;&lt; std::endl;
                  break;
  
              case Z_BUF_ERROR:
                  std::cerr &lt;&lt; "Buffer error!" &lt;&lt; std::endl;
                  break;
  
              default:
                  std::cerr &lt;&lt; "Unknown error: " &lt;&lt; error &lt;&lt; std::endl;
                  break;
          }
  
          return 0;
      }
  
      *compressedSize = static_cast&lt;unsigned long&gt;(outBufferSize);
  
      return reinterpret_cast&lt;char*&gt;(outBuffer);
  }
  </code></pre>
  
  <p>I hit 'Unknown error: -2' which turns out to be ZLIB_STREAM_ERROR. I can't figure out the problem. All the variables seem to be correct.</p>