summaryrefslogtreecommitdiffstats
path: root/tests/fullbench.c
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 /tests/fullbench.c
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 'tests/fullbench.c')
-rw-r--r--tests/fullbench.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/tests/fullbench.c b/tests/fullbench.c
index 7d74d3f..77f475b 100644
--- a/tests/fullbench.c
+++ b/tests/fullbench.c
@@ -399,25 +399,25 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
char* compressed_buff=NULL;
const char* const inFileName = fileNamesTable[fileIdx++];
FILE* const inFile = fopen( inFileName, "rb" );
- U64 inFileSize;
- size_t benchedSize;
+ U64 const inFileSize = UTIL_getFileSize(inFileName);
+ size_t benchedSize = BMK_findMaxMem(inFileSize*2) / 2; /* because 2 buffers */
int nbChunks;
int maxCompressedChunkSize;
size_t readSize;
int compressedBuffSize;
U32 crcOriginal;
- /* Check file existence */
- if (inFile==NULL) { DISPLAY( "Pb opening %s\n", inFileName); return 11; }
+ /* Check infile pre-requisites */
+ if (inFile==NULL) { DISPLAY("Pb opening %s \n", inFileName); return 11; }
+ if (inFileSize==0) { DISPLAY("file is empty \n"); fclose(inFile); return 11; }
+ if (benchedSize==0) { DISPLAY("not enough memory \n"); fclose(inFile); return 11; }
/* Memory size adjustments */
- inFileSize = UTIL_getFileSize(inFileName);
- if (inFileSize==0) { DISPLAY( "file is empty\n"); fclose(inFile); return 11; }
- benchedSize = BMK_findMaxMem(inFileSize*2) / 2; /* because 2 buffers */
- if (benchedSize==0) { DISPLAY( "not enough memory\n"); fclose(inFile); return 11; }
if ((U64)benchedSize > inFileSize) benchedSize = (size_t)inFileSize;
- if (benchedSize < inFileSize)
- DISPLAY("Not enough memory for '%s' full size; testing %i MB only...\n", inFileName, (int)(benchedSize>>20));
+ if (benchedSize < inFileSize) {
+ DISPLAY("Not enough memory for '%s' full size; testing %i MB only... \n",
+ inFileName, (int)(benchedSize>>20));
+ }
/* Allocation */
chunkP = (struct chunkParameters*) malloc(((benchedSize / (size_t)g_chunkSize)+1) * sizeof(struct chunkParameters));
@@ -427,7 +427,7 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
compressedBuffSize = nbChunks * maxCompressedChunkSize;
compressed_buff = (char*)malloc((size_t)compressedBuffSize);
if(!chunkP || !orig_buff || !compressed_buff) {
- DISPLAY("\nError: not enough memory!\n");
+ DISPLAY("\nError: not enough memory! \n");
fclose(inFile);
free(orig_buff);
free(compressed_buff);
@@ -475,7 +475,7 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
size_t remaining = benchedSize;
char* in = orig_buff;
char* out = compressed_buff;
- nbChunks = (int) (((int)benchedSize + (g_chunkSize-1))/ g_chunkSize);
+ assert(nbChunks >= 1);
for (i=0; i<nbChunks; i++) {
chunkP[i].id = (U32)i;
chunkP[i].origBuffer = in; in += g_chunkSize;