summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Collet <yann.collet.73@gmail.com>2015-04-12 08:29:52 (GMT)
committerYann Collet <yann.collet.73@gmail.com>2015-04-12 08:29:52 (GMT)
commit81fdd9df23821d5db8331e66478e2617b470820c (patch)
tree654af31034b520af11aec51d366d8255c96aaaba
parent66b8a4a8afe72ac37a26199249a78a5349201472 (diff)
downloadlz4-81fdd9df23821d5db8331e66478e2617b470820c.zip
lz4-81fdd9df23821d5db8331e66478e2617b470820c.tar.gz
lz4-81fdd9df23821d5db8331e66478e2617b470820c.tar.bz2
Fixed a few Valgrind warnings
-rw-r--r--lib/lz4.c5
-rw-r--r--lib/lz4hc.c2
-rw-r--r--programs/fullbench.c52
3 files changed, 21 insertions, 38 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index d6fdcd9..e57d080 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -756,6 +756,7 @@ int LZ4_freeStream (LZ4_stream_t* LZ4_stream)
}
+#define HASH_UNIT sizeof(size_t)
int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize)
{
LZ4_stream_t_internal* dict = (LZ4_stream_t_internal*) LZ4_dict;
@@ -765,7 +766,7 @@ int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize)
if (dict->initCheck) LZ4_resetStream(LZ4_dict); /* Uninitialized structure detected */
- if (dictSize < MINMATCH)
+ if (dictSize < HASH_UNIT)
{
dict->dictionary = NULL;
dict->dictSize = 0;
@@ -778,7 +779,7 @@ int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize)
dict->dictSize = (U32)(dictEnd - p);
dict->currentOffset += dict->dictSize;
- while (p <= dictEnd-MINMATCH)
+ while (p <= dictEnd-HASH_UNIT)
{
LZ4_putPosition(p, dict, byU32, base);
p+=3;
diff --git a/lib/lz4hc.c b/lib/lz4hc.c
index 234e1af..4f1272c 100644
--- a/lib/lz4hc.c
+++ b/lib/lz4hc.c
@@ -656,7 +656,7 @@ int LZ4_saveDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, char* safeBuffer, int dictS
if (dictSize > 64 KB) dictSize = 64 KB;
if (dictSize < 4) dictSize = 0;
if (dictSize > prefixSize) dictSize = prefixSize;
- memcpy(safeBuffer, streamPtr->end - dictSize, dictSize);
+ memmove(safeBuffer, streamPtr->end - dictSize, dictSize);
{
U32 endIndex = (U32)(streamPtr->end - streamPtr->base);
streamPtr->end = (const BYTE*)safeBuffer + dictSize;
diff --git a/programs/fullbench.c b/programs/fullbench.c
index 4ffae59..51e0e9a 100644
--- a/programs/fullbench.c
+++ b/programs/fullbench.c
@@ -539,10 +539,16 @@ static int local_LZ4F_decompress(const char* in, char* out, int inSize, int outS
int fullSpeedBench(char** fileNamesTable, int nbFiles)
{
int fileIdx=0;
- char* orig_buff;
+ char* orig_buff = NULL;
+ struct chunkParameters* chunkP = NULL;
+ char* compressed_buff=NULL;
size_t errorCode;
int benchStatus = 0;
+ /* Init */
+ errorCode = LZ4F_createDecompressionContext(&g_dCtx, LZ4F_VERSION);
+ if (LZ4F_isError(errorCode)) { DISPLAY("dctx allocation issue \n"); CLEANEXIT(10); }
+
/* Loop for each fileName */
while (fileIdx<nbFiles)
{
@@ -552,55 +558,32 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles)
size_t benchedSize;
int nbChunks;
int maxCompressedChunkSize;
- struct chunkParameters* chunkP;
size_t readSize;
- char* compressed_buff; int compressedBuffSize;
+ int compressedBuffSize;
U32 crcOriginal;
-
/* Check file existence */
inFileName = fileNamesTable[fileIdx++];
inFile = fopen( inFileName, "rb" );
- if (inFile==NULL)
- {
- DISPLAY( "Pb opening %s\n", inFileName);
- return 11;
- }
+ if (inFile==NULL) { DISPLAY( "Pb opening %s\n", inFileName); CLEANEXIT(11); }
/* Memory size adjustments */
inFileSize = BMK_GetFileSize(inFileName);
- if (inFileSize==0) { DISPLAY( "file is empty\n"); return 11; }
+ if (inFileSize==0) { DISPLAY( "file is empty\n"); CLEANEXIT(11); }
benchedSize = (size_t) BMK_findMaxMem(inFileSize*2) / 2; /* because 2 buffers */
- if (benchedSize==0) { DISPLAY( "not enough memory\n"); return 11; }
+ if (benchedSize==0) { DISPLAY( "not enough memory\n"); CLEANEXIT(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));
/* Allocation */
- errorCode = LZ4F_createDecompressionContext(&g_dCtx, LZ4F_VERSION);
- if (LZ4F_isError(errorCode))
- {
- DISPLAY("dctx allocation issue \n");
- fclose(inFile);
- return 10;
- }
chunkP = (struct chunkParameters*) malloc(((benchedSize / (size_t)chunkSize)+1) * sizeof(struct chunkParameters));
orig_buff = (char*) malloc((size_t)benchedSize);
nbChunks = (int) (((int)benchedSize + (chunkSize-1))/ chunkSize);
maxCompressedChunkSize = LZ4_compressBound(chunkSize);
compressedBuffSize = nbChunks * maxCompressedChunkSize;
compressed_buff = (char*)malloc((size_t)compressedBuffSize);
-
-
- if(!orig_buff || !compressed_buff)
- {
- DISPLAY("\nError: not enough memory!\n");
- free(orig_buff);
- free(compressed_buff);
- free(chunkP);
- fclose(inFile);
- return 12;
- }
+ if(!orig_buff || !compressed_buff) { DISPLAY("\nError: not enough memory!\n"); fclose(inFile); CLEANEXIT(12); }
/* Fill in src buffer */
DISPLAY("Loading %s... \r", inFileName);
@@ -813,15 +796,14 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles)
DISPLAY("%2i-%-29.29s :%10i -> %7.1f MB/s\n", dAlgNb, dName, (int)benchedSize, (double)benchedSize / bestTime / 1000.);
}
-
}
+ }
_clean_up:
- free(orig_buff);
- free(compressed_buff);
- free(chunkP);
- LZ4F_freeDecompressionContext(g_dCtx);
- }
+ free(orig_buff);
+ free(compressed_buff);
+ free(chunkP);
+ LZ4F_freeDecompressionContext(g_dCtx);
if (BMK_pause) { printf("press enter...\n"); (void)getchar(); }