diff options
author | Yann Collet <yann.collet.73@gmail.com> | 2015-06-29 05:53:42 (GMT) |
---|---|---|
committer | Yann Collet <yann.collet.73@gmail.com> | 2015-06-29 05:53:42 (GMT) |
commit | 8901dcdc9db3ea5d47900be903dfdb5070dc6b21 (patch) | |
tree | 531a9830e26509f2d383480009b5e86f00f10c23 /programs/lz4io.c | |
parent | 1098d897a0c410306f0ac547c4b92e02922f8ddb (diff) | |
download | lz4-8901dcdc9db3ea5d47900be903dfdb5070dc6b21.zip lz4-8901dcdc9db3ea5d47900be903dfdb5070dc6b21.tar.gz lz4-8901dcdc9db3ea5d47900be903dfdb5070dc6b21.tar.bz2 |
removed one malloc
Diffstat (limited to 'programs/lz4io.c')
-rw-r--r-- | programs/lz4io.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/programs/lz4io.c b/programs/lz4io.c index d92634a..be2dc5d 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -1013,6 +1013,7 @@ int LZ4IO_decompressFilename(const char* input_filename, const char* output_file } +#define MAXSUFFIXSIZE 8 int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix) { int i; @@ -1021,17 +1022,18 @@ int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSiz char* outFileName = (char*)malloc(FNSPACE); size_t ofnSize = FNSPACE; const size_t suffixSize = strlen(suffix); - char* ifnSuffix = (char*)malloc(suffixSize + 1); + const char* suffixPtr; dRess_t ress; + if (outFileName==NULL) exit(1); /* not enough memory */ ress = LZ4IO_createDResources(); for (i=0; i<ifntSize; i++) { size_t ifnSize = strlen(inFileNamesTable[i]); - strcpy(ifnSuffix, inFileNamesTable[i] + ifnSize - suffixSize); - if (ofnSize <= ifnSize-suffixSize+1) { free(outFileName); ofnSize = ifnSize + 20; outFileName = (char*)malloc(ofnSize); } - if (ifnSize <= suffixSize || strcmp(ifnSuffix, suffix) != 0) + suffixPtr = inFileNamesTable[i] + ifnSize - suffixSize; + if (ofnSize <= ifnSize-suffixSize+1) { free(outFileName); ofnSize = ifnSize + 20; outFileName = (char*)malloc(ofnSize); if (outFileName==NULL) exit(1); } + if (ifnSize <= suffixSize || strcmp(suffixPtr, suffix) != 0) { DISPLAYLEVEL(1, "File extension doesn't match expected LZ4_EXTENSION (%4s); will not process file: %s\n", suffix, inFileNamesTable[i]); skippedFiles++; @@ -1045,6 +1047,5 @@ int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSiz LZ4IO_freeDResources(ress); free(outFileName); - free(ifnSuffix); return missingFiles + skippedFiles; } |