summaryrefslogtreecommitdiffstats
path: root/lib/lz4hc.c
diff options
context:
space:
mode:
authorYann Collet <yann.collet.73@gmail.com>2020-09-29 05:37:20 (GMT)
committerYann Collet <cyan@fb.com>2020-09-30 00:20:52 (GMT)
commitad2d2764c71a3d993f8da415186dd4d6345ceea3 (patch)
tree99fdf5377f2a76d9c3a0c996c3ddd33c39459a0c /lib/lz4hc.c
parent78f4fdbb89e71325cedc751e1f7c2403bb43c3f4 (diff)
downloadlz4-ad2d2764c71a3d993f8da415186dd4d6345ceea3.zip
lz4-ad2d2764c71a3d993f8da415186dd4d6345ceea3.tar.gz
lz4-ad2d2764c71a3d993f8da415186dd4d6345ceea3.tar.bz2
fix minor static analyzer warnings
detected by scan-build, cppcheck and advanved compilation flags fix #786
Diffstat (limited to 'lib/lz4hc.c')
-rw-r--r--lib/lz4hc.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/lz4hc.c b/lib/lz4hc.c
index 6e4d732..28b91f7 100644
--- a/lib/lz4hc.c
+++ b/lib/lz4hc.c
@@ -270,7 +270,7 @@ LZ4HC_InsertAndGetWiderMatch (
DEBUGLOG(7, "First match at index %u / %u (lowestMatchIndex)",
matchIndex, lowestMatchIndex);
- while ((matchIndex>=lowestMatchIndex) && (nbAttempts)) {
+ while ((matchIndex>=lowestMatchIndex) && (nbAttempts>0)) {
int matchLength=0;
nbAttempts--;
assert(matchIndex < ipIndex);
@@ -410,7 +410,7 @@ LZ4HC_InsertAndGetWiderMatch (
} /* while ((matchIndex>=lowestMatchIndex) && (nbAttempts)) */
if ( dict == usingDictCtxHc
- && nbAttempts
+ && nbAttempts > 0
&& ipIndex - lowestMatchIndex < LZ4_DISTANCE_MAX) {
size_t const dictEndOffset = (size_t)(dictCtx->end - dictCtx->base);
U32 dictMatchIndex = dictCtx->hashTable[LZ4HC_hashPtr(ip)];
@@ -544,7 +544,7 @@ LZ4_FORCE_INLINE int LZ4HC_compress_hashChain (
char* const dest,
int* srcSizePtr,
int const maxOutputSize,
- unsigned maxNbAttempts,
+ int maxNbAttempts,
const limitedOutput_directive limit,
const dictCtx_directive dict
)
@@ -799,7 +799,7 @@ LZ4_FORCE_INLINE int LZ4HC_compress_generic_internal (
typedef enum { lz4hc, lz4opt } lz4hc_strat_e;
typedef struct {
lz4hc_strat_e strat;
- U32 nbSearches;
+ int nbSearches;
U32 targetLength;
} cParams_t;
static const cParams_t clTable[LZ4HC_CLEVEL_MAX+1] = {
@@ -839,7 +839,7 @@ LZ4_FORCE_INLINE int LZ4HC_compress_generic_internal (
assert(cParam.strat == lz4opt);
result = LZ4HC_compress_optimal(ctx,
src, dst, srcSizePtr, dstCapacity,
- (int)cParam.nbSearches, cParam.targetLength, limit,
+ cParam.nbSearches, cParam.targetLength, limit,
cLevel == LZ4HC_CLEVEL_MAX, /* ultra mode */
dict, favor);
}
@@ -981,10 +981,10 @@ int LZ4_compress_HC_destSize(void* state, const char* source, char* dest, int* s
/* allocation */
LZ4_streamHC_t* LZ4_createStreamHC(void)
{
- LZ4_streamHC_t* const LZ4_streamHCPtr = (LZ4_streamHC_t*)ALLOC(sizeof(LZ4_streamHC_t));
- if (LZ4_streamHCPtr==NULL) return NULL;
- LZ4_initStreamHC(LZ4_streamHCPtr, sizeof(*LZ4_streamHCPtr)); /* full initialization, malloc'ed buffer can be full of garbage */
- return LZ4_streamHCPtr;
+ LZ4_streamHC_t* state = (LZ4_streamHC_t*)ALLOC(sizeof(LZ4_streamHC_t));
+ if (state==NULL) return NULL;
+ state = LZ4_initStreamHC(state, sizeof(*state)); /* full initialization, malloc'ed buffer can be full of garbage */
+ return state;
}
int LZ4_freeStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr)
@@ -1347,7 +1347,6 @@ static int LZ4HC_compress_optimal ( LZ4HC_CCtx_internal* ctx,
if (sufficient_len >= LZ4_OPT_NUM) sufficient_len = LZ4_OPT_NUM-1;
/* Main Loop */
- assert(ip - anchor < LZ4_MAX_INPUT_SIZE);
while (ip <= mflimit) {
int const llen = (int)(ip - anchor);
int best_mlen, best_off;