summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYann Collet <yann.collet.73@gmail.com>2020-11-08 18:08:43 -0800
committerYann Collet <yann.collet.73@gmail.com>2020-11-08 18:08:43 -0800
commit2a2b10f19242aedc8598b74bcb4614d03485c3c0 (patch)
treeea4c5f4fbe2d76d1f16ad05d4396310b23d1cd83
parente251a840253c5564364bf5c8c662a6fe623dc3e9 (diff)
downloadlz4-2a2b10f19242aedc8598b74bcb4614d03485c3c0.tar.gz
lz4-2a2b10f19242aedc8598b74bcb4614d03485c3c0.tar.bz2
lz4-2a2b10f19242aedc8598b74bcb4614d03485c3c0.zip
fixed remaining ubsan warnings
-rw-r--r--lib/lz4.c2
-rw-r--r--lib/lz4hc.c7
2 files changed, 6 insertions, 3 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index 427673e..b066c55 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -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;
}