diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/H5Zszip.c | 45 |
1 files changed, 16 insertions, 29 deletions
diff --git a/src/H5Zszip.c b/src/H5Zszip.c index ac11dd1..df27a2f 100644 --- a/src/H5Zszip.c +++ b/src/H5Zszip.c @@ -269,29 +269,15 @@ H5Z_filter_szip (unsigned flags, size_t cd_nelmts, const unsigned cd_values[], UINT32DECODE(newbuf,stored_nalloc); H5_ASSIGN_OVERFLOW(nalloc,stored_nalloc,uint32_t,size_t); - /* Check for uncompressed buffer */ - if(nalloc==0) { - /* Set the correct number of bytes to allocate */ - nalloc=nbytes-4; - - /* Allocate space for the uncompressed buffer */ - if(NULL==(outbuf = H5MM_malloc(nalloc))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed for szip decompression"); - - /* Copy over the uncompressed data */ - HDmemcpy((void*)outbuf, (void*)newbuf, nalloc); - } /* end if */ - else { - /* Allocate space for the uncompressed buffer */ - if(NULL==(outbuf = H5MM_malloc(nalloc))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed for szip decompression"); - - /* Decompress the buffer */ - size_out=nalloc; - if(SZ_BufftoBuffDecompress(outbuf, &size_out, newbuf, nbytes-4, &sz_param) != SZ_OK) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "szip_filter: decompression failed"); - assert(size_out==nalloc); - } /* end else */ + /* Allocate space for the uncompressed buffer */ + if(NULL==(outbuf = H5MM_malloc(nalloc))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed for szip decompression"); + + /* Decompress the buffer */ + size_out=nalloc; + if(SZ_BufftoBuffDecompress(outbuf, &size_out, newbuf, nbytes-4, &sz_param) != SZ_OK) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "szip_filter: decompression failed"); + assert(size_out==nalloc); /* Free the input buffer */ H5MM_xfree(*buf); @@ -306,19 +292,20 @@ H5Z_filter_szip (unsigned flags, size_t cd_nelmts, const unsigned cd_values[], else { unsigned char *dst = NULL; /* Temporary pointer to new output buffer */ - /* Allocate space for the compressed buffer (assume it won't get bigger) */ + /* Allocate space for the compressed buffer & header (assume data won't get bigger) */ if(NULL==(dst=outbuf = H5MM_malloc(nbytes+4))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "unable to allocate szip destination buffer"); - /* Compress the buffer */ - size_out = nbytes; - if(SZ_OK!= SZ_BufftoBuffCompress(outbuf+4, &size_out, *buf, nbytes, &sz_param)) - HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "overflow"); - /* Encode the uncompressed length */ H5_CHECK_OVERFLOW(nbytes,size_t,uint32_t); UINT32ENCODE(dst,nbytes); + /* Compress the buffer */ + size_out = nbytes; + if(SZ_OK!= SZ_BufftoBuffCompress(dst, &size_out, *buf, nbytes, &sz_param)) + HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "overflow"); + assert(size_out<=nbytes); + /* Free the input buffer */ H5MM_xfree(*buf); |