This commit is contained in:
twinaphex 2014-09-13 02:36:13 +02:00
parent 64e77f1224
commit 0c1a2dd8d7
5 changed files with 40 additions and 44 deletions

View File

@ -98,8 +98,11 @@ int rl_fnmatch(const char *pattern, const char *string, int flags)
/* Match following character verbatim */ /* Match following character verbatim */
case '\\': case '\\':
c++; c++;
/* Dangling escape at end of pattern */ /* Dangling escape at end of pattern.
if (*c == '\0') /* FIXME: Was c == '\0' (makes no sense). Not sure if c == NULL or *c == '\0' is intended. Assuming *c due to c++ right before. */ * FIXME: Was c == '\0' (makes no sense).
* Not sure if c == NULL or *c == '\0'
* is intended. Assuming *c due to c++ right before. */
if (*c == '\0')
return FNM_NOMATCH; return FNM_NOMATCH;
default: default:
if (*c != *string) if (*c != *string)

View File

@ -274,7 +274,8 @@ static struct rxml_node *rxml_parse_node(const char **ptr_)
goto error; goto error;
} }
node->data = strdup_range(cdata_start + strlen("<![CDATA["), cdata_end); node->data = strdup_range(cdata_start +
strlen("<![CDATA["), cdata_end);
} }
else if (closing_start && closing_start == child_start) /* Simple Data */ else if (closing_start && closing_start == child_start) /* Simple Data */
node->data = strdup_range(closing + 1, closing_start); node->data = strdup_range(closing + 1, closing_start);
@ -288,7 +289,8 @@ static struct rxml_node *rxml_parse_node(const char **ptr_)
const char *first_start = strchr(ptr, '<'); const char *first_start = strchr(ptr, '<');
const char *first_closing = strstr(ptr, "</"); const char *first_closing = strstr(ptr, "</");
while (first_start && first_closing && first_start < first_closing) while (first_start &&
first_closing && first_start < first_closing)
{ {
struct rxml_node *new_node = rxml_parse_node(&ptr); struct rxml_node *new_node = rxml_parse_node(&ptr);
if (!new_node) if (!new_node)

View File

@ -134,7 +134,8 @@ static SRes Utf16_To_Char(CBuf *buf, const UInt16 *s, int fileMode)
AreFileApisANSI() ? CP_ACP : CP_OEMCP AreFileApisANSI() ? CP_ACP : CP_OEMCP
#endif #endif
) : CP_OEMCP, ) : CP_OEMCP,
0, (LPCWSTR)s, len, (char *)buf->data, size, &defaultChar, &defUsed); 0, (LPCWSTR)s, len, (char *)buf->data,
size, &defaultChar, &defUsed);
if (numChars == 0 || numChars >= size) if (numChars == 0 || numChars >= size)
return SZ_ERROR_FAIL; return SZ_ERROR_FAIL;
buf->data[numChars] = 0; buf->data[numChars] = 0;
@ -277,7 +278,7 @@ int read_7zip_file(const char * archive_path,
if (res == SZ_OK && file_found == true) if (res == SZ_OK && file_found == true)
return outsize; return outsize;
//Error handling: /* Error handling */
if (!file_found) if (!file_found)
RARCH_ERR("File %s not found in %s\n",relative_path,archive_path); RARCH_ERR("File %s not found in %s\n",relative_path,archive_path);
else if (res == SZ_ERROR_UNSUPPORTED) else if (res == SZ_ERROR_UNSUPPORTED)
@ -412,27 +413,16 @@ struct string_list *compressed_7zip_file_list_new(const char *path,
{ {
/* Error handling */ /* Error handling */
if (res == SZ_ERROR_UNSUPPORTED) if (res == SZ_ERROR_UNSUPPORTED)
{
RARCH_ERR("7Zip decoder doesn't support this archive\n"); RARCH_ERR("7Zip decoder doesn't support this archive\n");
goto error;
}
else if (res == SZ_ERROR_MEM) else if (res == SZ_ERROR_MEM)
{
RARCH_ERR("7Zip decoder could not allocate memory\n"); RARCH_ERR("7Zip decoder could not allocate memory\n");
goto error;
}
else if (res == SZ_ERROR_CRC) else if (res == SZ_ERROR_CRC)
{
RARCH_ERR("7Zip decoder encountered a CRC error in the archive\n"); RARCH_ERR("7Zip decoder encountered a CRC error in the archive\n");
goto error;
}
else else
{
RARCH_ERR( RARCH_ERR(
"\nUnspecified error in 7-ZIP archive, error number was: #%d\n", "\nUnspecified error in 7-ZIP archive, error number was: #%d\n",
res); res);
goto error; goto error;
}
} }
string_list_free(ext_list); string_list_free(ext_list);
@ -446,5 +436,4 @@ error:
string_list_free(list); string_list_free(list);
string_list_free(ext_list); string_list_free(ext_list);
return NULL; return NULL;
} }

View File

@ -27,11 +27,14 @@
#include "../deps/rzlib/unzip.h" #include "../deps/rzlib/unzip.h"
/* Extract the relative path relative_path from a zip archive archive_path and allocate a buf for it to write it in. */ /* Extract the relative path relative_path from a
* zip archive archive_path and allocate a buf for it to write it in. */
/* This code is inspired by: /* This code is inspired by:
* http://stackoverflow.com/questions/10440113/simple-way-to-unzip-a-zip-file-using-zlib * stackoverflow.com/questions/10440113/simple-way-to-unzip-a-zip-file-using-zlib
*/ */
int read_zip_file(const char * archive_path, const char *relative_path, void **buf)
int read_zip_file(const char * archive_path,
const char *relative_path, void **buf)
{ {
ssize_t bytes_read = -1; ssize_t bytes_read = -1;
bool finished_reading = false; bool finished_reading = false;
@ -47,7 +50,8 @@ int read_zip_file(const char * archive_path, const char *relative_path, void **b
if ( unzGetGlobalInfo( zipfile, &global_info ) != UNZ_OK ) if ( unzGetGlobalInfo( zipfile, &global_info ) != UNZ_OK )
{ {
RARCH_ERR("Could not get global zipfile info of %s." RARCH_ERR("Could not get global zipfile info of %s."
"Could be only a gzip file without the zip part.\n",archive_path); "Could be only a gzip file without the zip part.\n",
archive_path);
unzClose( zipfile ); unzClose( zipfile );
return -1; return -1;
} }
@ -66,7 +70,8 @@ int read_zip_file(const char * archive_path, const char *relative_path, void **b
PATH_MAX, PATH_MAX,
NULL, 0, NULL, 0 ) != UNZ_OK ) NULL, 0, NULL, 0 ) != UNZ_OK )
{ {
RARCH_ERR("Could not read file info in zip %s.\n",archive_path); RARCH_ERR("Could not read file info in zip %s.\n",
archive_path);
unzClose( zipfile ); unzClose( zipfile );
return -1; return -1;
} }
@ -83,7 +88,8 @@ int read_zip_file(const char * archive_path, const char *relative_path, void **b
/* We found the correct file in the zip, now extract it to *buf */ /* We found the correct file in the zip, now extract it to *buf */
if ( unzOpenCurrentFile( zipfile ) != UNZ_OK ) if ( unzOpenCurrentFile( zipfile ) != UNZ_OK )
{ {
RARCH_ERR("The file %s in %s could not be read.\n",relative_path,archive_path); RARCH_ERR("The file %s in %s could not be read.\n",
relative_path, archive_path);
unzClose( zipfile ); unzClose( zipfile );
return -1; return -1;
} }
@ -94,8 +100,10 @@ int read_zip_file(const char * archive_path, const char *relative_path, void **b
bytes_read = unzReadCurrentFile( zipfile, *buf, file_info.uncompressed_size ); bytes_read = unzReadCurrentFile( zipfile, *buf, file_info.uncompressed_size );
if (bytes_read != file_info.uncompressed_size) if (bytes_read != file_info.uncompressed_size)
{ {
RARCH_ERR("We tried to read %d bytes, but only got %d of file %s in zip %s.\n", RARCH_ERR(
(unsigned int) file_info.uncompressed_size,(int)bytes_read,relative_path,archive_path); "We tried to read %d bytes, but only got %d of file %s in zip %s.\n",
(unsigned int) file_info.uncompressed_size, (int)bytes_read,
relative_path, archive_path);
free(*buf); free(*buf);
unzCloseCurrentFile( zipfile ); unzCloseCurrentFile( zipfile );
unzClose( zipfile ); unzClose( zipfile );
@ -112,7 +120,9 @@ int read_zip_file(const char * archive_path, const char *relative_path, void **b
{ {
if ( unzGoToNextFile( zipfile ) != UNZ_OK ) if ( unzGoToNextFile( zipfile ) != UNZ_OK )
{ {
RARCH_ERR( "Could not iterate to next file in %s. Zipfile might be corrupt.\n",archive_path ); RARCH_ERR(
"Could not iterate to next file in %s. Zipfile might be corrupt.\n",
archive_path );
unzClose( zipfile ); unzClose( zipfile );
return -1; return -1;
} }
@ -162,7 +172,8 @@ struct string_list *compressed_zip_file_list_new(const char *path,
if ( unzGetGlobalInfo( zipfile, &global_info ) != UNZ_OK ) if ( unzGetGlobalInfo( zipfile, &global_info ) != UNZ_OK )
{ {
RARCH_ERR("Could not get global zipfile info of %s." RARCH_ERR("Could not get global zipfile info of %s."
"Could be only a gzip file without the zip part.\n",path); "Could be only a gzip file without the zip part.\n",
path);
unzClose( zipfile ); unzClose( zipfile );
return NULL; return NULL;
} }

View File

@ -179,9 +179,7 @@ long read_file(const char *path, void **buf)
* */ * */
#ifdef HAVE_COMPRESSION #ifdef HAVE_COMPRESSION
if (path_contains_compressed_file(path)) if (path_contains_compressed_file(path))
{
return read_compressed_file(path,buf); return read_compressed_file(path,buf);
}
#endif #endif
return read_generic_file(path,buf); return read_generic_file(path,buf);
} }
@ -442,15 +440,11 @@ struct string_list *compressed_file_list_new(const char *path,
const char* file_ext = path_get_extension(path); const char* file_ext = path_get_extension(path);
#ifdef HAVE_7ZIP #ifdef HAVE_7ZIP
if (strcasecmp(file_ext,"7z") == 0) if (strcasecmp(file_ext,"7z") == 0)
{
return compressed_7zip_file_list_new(path,ext); return compressed_7zip_file_list_new(path,ext);
}
#endif #endif
#ifdef HAVE_ZLIB #ifdef HAVE_ZLIB
if (strcasecmp(file_ext,"zip") == 0) if (strcasecmp(file_ext,"zip") == 0)
{
return compressed_zip_file_list_new(path,ext); return compressed_zip_file_list_new(path,ext);
}
#endif #endif
#endif #endif
@ -683,15 +677,11 @@ bool path_is_compressed_file(const char* path)
const char* file_ext = path_get_extension(path); const char* file_ext = path_get_extension(path);
#ifdef HAVE_7ZIP #ifdef HAVE_7ZIP
if (strcmp(file_ext,"7z") == 0) if (strcmp(file_ext,"7z") == 0)
{
return true; return true;
}
#endif #endif
#ifdef HAVE_ZLIB #ifdef HAVE_ZLIB
if (strcmp(file_ext,"zip") == 0) if (strcmp(file_ext,"zip") == 0)
{
return true; return true;
}
#endif #endif
#endif #endif
@ -856,7 +846,7 @@ const char *path_basename(const char *path)
bool path_is_absolute(const char *path) bool path_is_absolute(const char *path)
{ {
#ifdef _WIN32 #ifdef _WIN32
// Many roads lead to Rome ... /* Many roads lead to Rome ... */
return path[0] == '/' || (strstr(path, "\\\\") == path) return path[0] == '/' || (strstr(path, "\\\\") == path)
|| strstr(path, ":/") || strstr(path, ":\\") || strstr(path, ":\\\\"); || strstr(path, ":/") || strstr(path, ":\\") || strstr(path, ":\\\\");
#else #else
@ -1003,10 +993,11 @@ void fill_pathname_expand_special(char *out_path,
} }
else if ((in_path[0] == ':') && else if ((in_path[0] == ':') &&
#ifdef _WIN32 #ifdef _WIN32
((in_path[1] == '/') || (in_path[1] == '\\'))) ((in_path[1] == '/') || (in_path[1] == '\\'))
#else #else
(in_path[1] == '/')) (in_path[1] == '/')
#endif #endif
)
{ {
char application_dir[PATH_MAX]; char application_dir[PATH_MAX];
fill_pathname_application_path(application_dir, sizeof(application_dir)); fill_pathname_application_path(application_dir, sizeof(application_dir));
@ -1040,8 +1031,8 @@ void fill_short_pathname_representation(char* out_rep,
*/ */
if(last_hash != NULL) if(last_hash != NULL)
{ {
/* We check whether something is actually after the hash to avoid /* We check whether something is actually
* going over the buffer. * after the hash to avoid going over the buffer.
*/ */
rarch_assert(strlen(last_hash) > 1); rarch_assert(strlen(last_hash) > 1);
strlcpy(out_rep,last_hash + 1, size); strlcpy(out_rep,last_hash + 1, size);