From 126a492fd5ee144e94551dd3bb43e243cd93ad17 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 21 Jan 2016 04:05:35 +0100 Subject: [PATCH] read_zip_file - cleanups --- file_ops.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/file_ops.c b/file_ops.c index 6fbc9f46cb..b1274e42eb 100644 --- a/file_ops.c +++ b/file_ops.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #ifdef HAVE_COMPRESSION @@ -384,8 +385,7 @@ static int read_zip_file(const char *archive_path, { /* Get info about current file. */ unz_file_info file_info; - char filename[PATH_MAX_LENGTH] = {0}; - char last_char = ' '; + char filename[PATH_MAX_LENGTH]; if (unzGetCurrentFileInfo( zipfile, @@ -395,11 +395,10 @@ static int read_zip_file(const char *archive_path, NULL, 0, NULL, 0 ) != UNZ_OK ) goto error; - /* Check if this entry is a directory or file. */ - last_char = filename[strlen(filename)-1]; - - /* We skip directories */ - if ( last_char == '/' || last_char == '\\' ) { } + if (path_is_directory(filename)) + { + /* We skip directories */ + } else if (string_is_equal(filename, relative_path)) { /* We found the correct file in the zip, @@ -411,6 +410,10 @@ static int read_zip_file(const char *archive_path, { /* Allocate outbuffer */ *buf = malloc(file_info.uncompressed_size + 1 ); + + if (!buf) + goto error; + bytes_read = unzReadCurrentFile(zipfile, *buf, file_info.uncompressed_size); if (bytes_read != (ssize_t)file_info.uncompressed_size)