summaryrefslogtreecommitdiffstats
path: root/programs
diff options
context:
space:
mode:
authorYann Collet <yann.collet.73@gmail.com>2020-09-29 05:37:20 (GMT)
committerYann Collet <yann.collet.73@gmail.com>2020-09-30 00:09:58 (GMT)
commit392809d66e6c98a7c8653a2a32f6843af0f4306a (patch)
tree7fa07658ee0a800faeb531bc29110ff69a9dd6cd /programs
parent78f4fdbb89e71325cedc751e1f7c2403bb43c3f4 (diff)
downloadlz4-392809d66e6c98a7c8653a2a32f6843af0f4306a.zip
lz4-392809d66e6c98a7c8653a2a32f6843af0f4306a.tar.gz
lz4-392809d66e6c98a7c8653a2a32f6843af0f4306a.tar.bz2
fix minor static analyzer warnings
detected by scan-build and cppcheck fix #786
Diffstat (limited to 'programs')
-rw-r--r--programs/lz4cli.c2
-rw-r--r--programs/lz4io.c22
-rw-r--r--programs/lz4io.h8
3 files changed, 15 insertions, 17 deletions
diff --git a/programs/lz4cli.c b/programs/lz4cli.c
index 67dcaa1..d7d4f81 100644
--- a/programs/lz4cli.c
+++ b/programs/lz4cli.c
@@ -395,7 +395,7 @@ int main(int argc, const char** argv)
if (!strcmp(argument, "--favor-decSpeed")) { LZ4IO_favorDecSpeed(prefs, 1); continue; }
if (!strcmp(argument, "--verbose")) { displayLevel++; continue; }
if (!strcmp(argument, "--quiet")) { if (displayLevel) displayLevel--; continue; }
- if (!strcmp(argument, "--version")) { DISPLAYOUT(WELCOME_MESSAGE); return 0; }
+ if (!strcmp(argument, "--version")) { DISPLAYOUT(WELCOME_MESSAGE); goto _cleanup; }
if (!strcmp(argument, "--help")) { usage_advanced(exeName); goto _cleanup; }
if (!strcmp(argument, "--keep")) { LZ4IO_setRemoveSrcFile(prefs, 0); continue; } /* keep source file (default) */
if (!strcmp(argument, "--rm")) { LZ4IO_setRemoveSrcFile(prefs, 1); continue; }
diff --git a/programs/lz4io.c b/programs/lz4io.c
index 0f3507e..3ffc519 100644
--- a/programs/lz4io.c
+++ b/programs/lz4io.c
@@ -1291,7 +1291,7 @@ int LZ4IO_decompressMultipleFilenames(LZ4IO_prefs_t* const prefs,
size_t const suffixSize = strlen(suffix);
dRess_t ress = LZ4IO_createDResources(prefs);
- if (outFileName==NULL) return ifntSize; /* not enough memory */
+ if (outFileName==NULL) EXM_THROW(70, "Memory allocation error");
ress.dstFile = LZ4IO_openDstFile(prefs, stdoutmark);
for (i=0; i<ifntSize; i++) {
@@ -1305,7 +1305,7 @@ int LZ4IO_decompressMultipleFilenames(LZ4IO_prefs_t* const prefs,
free(outFileName);
ofnSize = ifnSize + 20;
outFileName = (char*)malloc(ofnSize);
- if (outFileName==NULL) return ifntSize;
+ if (outFileName==NULL) EXM_THROW(71, "Memory allocation error");
}
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]);
@@ -1458,7 +1458,7 @@ static const char* LZ4IO_baseName(const char* input_filename) {
const char* b = strrchr(input_filename, '/');
if (!b) b = strrchr(input_filename, '\\');
if (!b) return input_filename;
- return b ? b + 1 : b;
+ return b + 1;
}
/* Report frame/s information in verbose mode.
@@ -1472,7 +1472,9 @@ LZ4IO_getCompressedFileInfo(LZ4IO_cFileInfo_t* cfinfo, const char* input_filenam
LZ4IO_infoResult result = LZ4IO_format_not_known; /* default result (error) */
unsigned char buffer[LZ4F_HEADER_SIZE_MAX];
FILE* const finput = LZ4IO_openSrcFile(input_filename);
- cfinfo->fileSize = (finput == NULL) ? 0 : UTIL_getOpenFileSize(finput);
+
+ if (finput == NULL) return LZ4IO_not_a_file;
+ cfinfo->fileSize = UTIL_getOpenFileSize(finput);
while (!feof(finput)) {
LZ4IO_frameInfo_t frameInfo = LZ4IO_INIT_FRAMEINFO;
@@ -1560,8 +1562,7 @@ LZ4IO_getCompressedFileInfo(LZ4IO_cFileInfo_t* cfinfo, const char* input_filenam
totalBlocksSize + 4,
"-", "-");
result = LZ4IO_LZ4F_OK;
- }
- }
+ } }
break;
case LZ4IO_SKIPPABLE0:
frameInfo.frameType = skippableFrame;
@@ -1628,8 +1629,7 @@ int LZ4IO_displayCompressedFilesInfo(const char** inFileNames, size_t ifnIdx)
assert(op_result == LZ4IO_format_not_known);
DISPLAYLEVEL(1, "lz4: %s: File format not recognized \n", inFileNames[idx]);
return 0;
- }
- }
+ } }
DISPLAYLEVEL(3, "\n");
if (g_displayLevel < 3) {
/* Display Summary */
@@ -1648,10 +1648,8 @@ int LZ4IO_displayCompressedFilesInfo(const char** inFileNames, size_t ifnIdx)
DISPLAYOUT("%9s %s\n",
"-",
cfinfo.fileName);
- }
- }
- }
- }
+ } } } /* if (g_displayLevel < 3) */
+ } /* for (; idx < ifnIdx; idx++) */
return result;
}
diff --git a/programs/lz4io.h b/programs/lz4io.h
index b189e35..4763180 100644
--- a/programs/lz4io.h
+++ b/programs/lz4io.h
@@ -39,13 +39,13 @@
/* ************************************************** */
/* Special input/output values */
/* ************************************************** */
+#define stdinmark "stdin"
+#define stdoutmark "stdout"
#define NULL_OUTPUT "null"
-static const char stdinmark[] = "stdin";
-static const char stdoutmark[] = "stdout";
#ifdef _WIN32
-static const char nulmark[] = "nul";
+#define nulmark "nul"
#else
-static const char nulmark[] = "/dev/null";
+#define nulmark "/dev/null"
#endif
/* ************************************************** */