diff options
author | Yann Collet <Cyan4973@users.noreply.github.com> | 2020-11-09 04:47:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-09 04:47:19 (GMT) |
commit | b8cd01183f1cd255e8581b48f5225f338dfa8c39 (patch) | |
tree | a18e6df6225c4380d8a3f4f5774d0697c36b1b41 /lib | |
parent | be634559e3b6bb7bce77cc83ec2080b2bfb6c844 (diff) | |
parent | c76564b944d1fe6e4ffc6dc3d002becfc3c74b5d (diff) | |
download | lz4-b8cd01183f1cd255e8581b48f5225f338dfa8c39.zip lz4-b8cd01183f1cd255e8581b48f5225f338dfa8c39.tar.gz lz4-b8cd01183f1cd255e8581b48f5225f338dfa8c39.tar.bz2 |
Merge pull request #945 from lz4/fix926
fixed remaining ubsan warnings
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lz4.c | 2 | ||||
-rw-r--r-- | lib/lz4hc.c | 7 |
2 files changed, 6 insertions, 3 deletions
@@ -1662,7 +1662,7 @@ int LZ4_saveDict (LZ4_stream_t* LZ4_dict, char* safeBuffer, int dictSize) if ((U32)dictSize > dict->dictSize) { dictSize = (int)dict->dictSize; } if (safeBuffer == NULL) assert(dictSize == 0); - if (safeBuffer != NULL) + if (dictSize > 0) memmove(safeBuffer, previousDictEnd - dictSize, dictSize); dict->dictionary = (const BYTE*)safeBuffer; diff --git a/lib/lz4hc.c b/lib/lz4hc.c index 8875f1a..286ff68 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -1164,13 +1164,16 @@ 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; - memmove(safeBuffer, streamPtr->end - dictSize, dictSize); + if (safeBuffer == NULL) assert(dictSize == 0); + if (dictSize > 0) + memmove(safeBuffer, streamPtr->end - dictSize, dictSize); { U32 const endIndex = (U32)(streamPtr->end - streamPtr->base); streamPtr->end = (const BYTE*)safeBuffer + dictSize; streamPtr->base = streamPtr->end - endIndex; streamPtr->dictLimit = endIndex - (U32)dictSize; streamPtr->lowLimit = endIndex - (U32)dictSize; - if (streamPtr->nextToUpdate < streamPtr->dictLimit) streamPtr->nextToUpdate = streamPtr->dictLimit; + if (streamPtr->nextToUpdate < streamPtr->dictLimit) + streamPtr->nextToUpdate = streamPtr->dictLimit; } return dictSize; } |