Skip to content

Commit

Permalink
fix bug in ascii version of gzip_util function
Browse files Browse the repository at this point in the history
Made ascii version implementation match the working unicode
implementation
  • Loading branch information
potmdehex committed Oct 20, 2015
1 parent bbbcf55 commit 5a91822
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions common/gzip_utils/gzip_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,35 +128,22 @@ int gu_decompress_mem(const void *src, long src_size, void **dst, long *dst_size
int gu_decompress_file_to_mem(const char *filename, void **dst, long *dst_size)
{
FILE *f = NULL;
int ret = 0;
gzFile gzf = NULL;
long size = 0;
void *buf = NULL;

// Open and read file contents
void *src = NULL;
long src_size = 0;

if (NULL == (f = fopen(filename, "rb"))) {
return 1;
}

fseek(f, 0, SEEK_END);
size = ftell(f);
src_size = ftell(f);
rewind(f);

buf = malloc(size);
if (NULL == buf) {
return 1;
}
fread(buf, 1, size, f);
src = malloc(src_size);
fread(src, 1, src_size, f);
fclose(f);

// Attempt decompress of file, returning a copy of buf in dst if
// decompression fails (ofc a bit unoptimized to not just use same pointer)
ret = gu_decompress_mem(buf, size, dst, dst_size);

free(buf);

return ret;
return gu_decompress_mem(src, src_size, dst, dst_size);
}

#ifdef _WIN32
Expand All @@ -166,8 +153,7 @@ int gu_decompress_file_to_mem_u(const wchar_t *filename, void **dst, long *dst_s
void *src = NULL;
long src_size = 0;

if (NULL == (f = _wfopen(filename, L"rb")))
{
if (NULL == (f = _wfopen(filename, L"rb"))) {
return 1;
}

Expand Down

0 comments on commit 5a91822

Please sign in to comment.