title: BUF_ERROR -5 return from uncompress ZLIB
body: <p>I am trying to unzip data in ZLIB using the uncompress function. the data to be decompressed is in a Char vector. the library was downloaded from github for C language. code below:</p>
  <pre><code> //C
   unsigned char out[20000], u_out[20000];
   size_t size_out;
   unsigned char* in = &quot;&quot;; //non inserisco i dati di partenza per privacy
   int err, i;
   long int ucompSize_out; 
   long int compSize_out; 
   size_out=sizeof(out);
  
   //codifica in base45
   err=base45_decode(out,&amp;size_out,in,strlen(in));
   printf(&quot;\nbase45(%s) &quot;, (char*)out);
   printf(&quot;\n%d&quot;,err);
      
  //decompressione zlib
  ucompSize_out= strlen(out)+1; 
  compSize_out= compressBound(ucompSize_out);
  err=uncompress ((Byte *)u_out, &amp;ucompSize_out, (const Byte *) out, compSize_out );
  printf(&quot;\nzlib(\&quot;%s\&quot;) &quot;, (char*)u_out);
  printf(&quot;\n%d&quot;,err);
  </code></pre>
  <p>when I run this code it returns me BUF_ERROR (-5). I read on the Zlib guide that it is a problem of space for output or input but I can not figure out how to fix it
  for completeness load also the functions recalled</p>
  <pre><code>int ZEXPORT uncompress2 (dest, destLen, source, sourceLen)
  Bytef *dest;
  uLongf *destLen;
  const Bytef *source;
  uLong *sourceLen;
  {
   z_stream stream;
  int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)
  z_streamp strm;
  int windowBits;
  const char *version;
  int stream_size;
  {
  int ret;
  struct inflate_state FAR *state;
  
  if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
      stream_size != (int)(sizeof(z_stream)))
      return Z_VERSION_ERROR;
  if (strm == Z_NULL) return Z_STREAM_ERROR;
  strm-&gt;msg = Z_NULL;                 /* in case we return an error */
  if (strm-&gt;zalloc == (alloc_func)0) {
  }
  if (strm-&gt;zfree == (free_func)0)
  
  state = (struct inflate_state FAR *)
          ZALLOC(strm, 1, sizeof(struct inflate_state));
  if (state == Z_NULL) return Z_MEM_ERROR;
  Tracev((stderr, &quot;inflate: allocated\n&quot;));
  strm-&gt;state = (struct internal_state FAR *)state;
  state-&gt;strm = strm;
  state-&gt;window = Z_NULL;
  state-&gt;mode = HEAD;     /* to pass state test in inflateReset2() */
  ret = inflateReset2(strm, windowBits);
  if (ret != Z_OK) {
      ZFREE(strm, state);
      strm-&gt;state = Z_NULL;
  }
   return ret;
  }
  
  int ZEXPORT inflateInit_(strm, version, stream_size)
  z_streamp strm;
  const char *version;
  int stream_size;
  {
   return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  }
   int err;
   const uInt max = (uInt)-1;
   uLong len, left;
   Byte buf[1];    /* for detection of incomplete stream when *destLen == 0 */
  
   len = *sourceLen;
   if (*destLen) {
      left = *destLen;
      *destLen = 0;
  }
  else {
      left = 1;
      dest = buf;
  }
  
  stream.next_in = (z_const Bytef *)source;
  stream.avail_in = 0;
  stream.zalloc = (alloc_func)0;
  stream.zfree = (free_func)0;
  stream.opaque = (voidpf)0;
  
  err = inflateInit2(&amp;stream);
  if (err != Z_OK) return err;
  
  stream.next_out = dest;
  stream.avail_out = 0;
  
  do {
      if (stream.avail_out == 0) {
          stream.avail_out = left &gt; (uLong)max ? max : (uInt)left;
          left -= stream.avail_out;
      }
      if (stream.avail_in == 0) {
          stream.avail_in = len &gt; (uLong)max ? max : (uInt)len;
          len -= stream.avail_in;
      }
      err = inflate(&amp;stream, Z_NO_FLUSH);
  } while (err == Z_OK);
  
  *sourceLen -= len + stream.avail_in;
  if (dest != buf)
      *destLen = stream.total_out;
  else if (stream.total_out &amp;&amp; err == Z_BUF_ERROR)
      left = 1;
  
  inflateEnd(&amp;stream);
  return err == Z_STREAM_END ? Z_OK :
         err == Z_NEED_DICT ? Z_DATA_ERROR  :
         err == Z_BUF_ERROR &amp;&amp; left + stream.avail_out ? Z_DATA_ERROR :
         err;
  }
  
  int ZEXPORT uncompress (dest, destLen, source, sourceLen)
  Bytef *dest;
  uLongf *destLen;
  const Bytef *source;
  uLong sourceLen;
  {
   return uncompress2(dest, destLen, source, &amp;sourceLen);
  }
  </code></pre>