aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYann Collet <Cyan4973@users.noreply.github.com>2022-07-31 15:28:28 +0200
committerGitHub <noreply@github.com>2022-07-31 15:28:28 +0200
commitd343a3685233f3c46c20bfeb7e8674de9d8175fc (patch)
treec0b757c6b5adad607fabde8fd36d951c8dcbeb81
parent6c8508323a87e7ce0bdea57ab18def17000effab (diff)
parent5d80375deddf33f2392eb2ea678cf2e203bb24fb (diff)
downloadlz4-d343a3685233f3c46c20bfeb7e8674de9d8175fc.tar.gz
Merge pull request #1123 from t-mat/memfunc-macros
New macro for memcpy, memmove and memset
-rw-r--r--lib/lz4.c31
-rw-r--r--lib/lz4hc.c8
2 files changed, 26 insertions, 13 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index 3f468d72..0dd337a3 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -206,7 +206,10 @@ void LZ4_free(void* p);
#endif
#include <string.h> /* memset, memcpy */
-#define MEM_INIT(p,v,s) memset((p),(v),(s))
+#if !defined(LZ4_memset)
+# define LZ4_memset(p,v,s) memset((p),(v),(s))
+#endif
+#define MEM_INIT(p,v,s) LZ4_memset((p),(v),(s))
/*-************************************
@@ -317,10 +320,20 @@ typedef enum {
* memcpy() as if it were standard compliant, so it can inline it in freestanding
* environments. This is needed when decompressing the Linux Kernel, for example.
*/
-#if defined(__GNUC__) && (__GNUC__ >= 4)
-#define LZ4_memcpy(dst, src, size) __builtin_memcpy(dst, src, size)
-#else
-#define LZ4_memcpy(dst, src, size) memcpy(dst, src, size)
+#if !defined(LZ4_memcpy)
+# if defined(__GNUC__) && (__GNUC__ >= 4)
+# define LZ4_memcpy(dst, src, size) __builtin_memcpy(dst, src, size)
+# else
+# define LZ4_memcpy(dst, src, size) memcpy(dst, src, size)
+# endif
+#endif
+
+#if !defined(LZ4_memmove)
+# if defined(__GNUC__) && (__GNUC__ >= 4)
+# define LZ4_memmove __builtin_memmove
+# else
+# define LZ4_memmove memmove
+# endif
#endif
static unsigned LZ4_isLittleEndian(void)
@@ -1703,7 +1716,7 @@ int LZ4_saveDict (LZ4_stream_t* LZ4_dict, char* safeBuffer, int dictSize)
if (dictSize > 0) {
const BYTE* const previousDictEnd = dict->dictionary + dict->dictSize;
assert(dict->dictionary);
- memmove(safeBuffer, previousDictEnd - dictSize, dictSize);
+ LZ4_memmove(safeBuffer, previousDictEnd - dictSize, dictSize);
}
dict->dictionary = (const BYTE*)safeBuffer;
@@ -1920,7 +1933,7 @@ LZ4_decompress_generic(
if (length <= (size_t)(lowPrefix-match)) {
/* match fits entirely within external dictionary : just copy */
- memmove(op, dictEnd - (lowPrefix-match), length);
+ LZ4_memmove(op, dictEnd - (lowPrefix-match), length);
op += length;
} else {
/* match stretches into both external dictionary and current block */
@@ -2064,7 +2077,7 @@ LZ4_decompress_generic(
goto _output_error;
}
}
- memmove(op, ip, length); /* supports overlapping memory regions; only matters for in-place decompression scenarios */
+ LZ4_memmove(op, ip, length); /* supports overlapping memory regions; only matters for in-place decompression scenarios */
ip += length;
op += length;
/* Necessarily EOF when !partialDecoding.
@@ -2109,7 +2122,7 @@ LZ4_decompress_generic(
if (length <= (size_t)(lowPrefix-match)) {
/* match fits entirely within external dictionary : just copy */
- memmove(op, dictEnd - (lowPrefix-match), length);
+ LZ4_memmove(op, dictEnd - (lowPrefix-match), length);
op += length;
} else {
/* match stretches into both external dictionary and current block */
diff --git a/lib/lz4hc.c b/lib/lz4hc.c
index 6b139fa6..e854cb44 100644
--- a/lib/lz4hc.c
+++ b/lib/lz4hc.c
@@ -755,7 +755,7 @@ _last_literals:
} else {
*op++ = (BYTE)(lastRunSize << ML_BITS);
}
- memcpy(op, anchor, lastRunSize);
+ LZ4_memcpy(op, anchor, lastRunSize);
op += lastRunSize;
}
@@ -894,7 +894,7 @@ LZ4HC_compress_generic_dictCtx (
ctx->dictCtx = NULL;
return LZ4HC_compress_generic_noDictCtx(ctx, src, dst, srcSizePtr, dstCapacity, cLevel, limit);
} else if (position == 0 && *srcSizePtr > 4 KB) {
- memcpy(ctx, ctx->dictCtx, sizeof(LZ4HC_CCtx_internal));
+ LZ4_memcpy(ctx, ctx->dictCtx, sizeof(LZ4HC_CCtx_internal));
LZ4HC_setExternalDict(ctx, (const BYTE *)src);
ctx->compressionLevel = (short)cLevel;
return LZ4HC_compress_generic_noDictCtx(ctx, src, dst, srcSizePtr, dstCapacity, cLevel, limit);
@@ -1177,7 +1177,7 @@ int LZ4_saveDictHC (LZ4_streamHC_t* LZ4_streamHCPtr, char* safeBuffer, int dictS
if (dictSize > prefixSize) dictSize = prefixSize;
if (safeBuffer == NULL) assert(dictSize == 0);
if (dictSize > 0)
- memmove(safeBuffer, streamPtr->end - dictSize, dictSize);
+ LZ4_memmove(safeBuffer, streamPtr->end - dictSize, dictSize);
{ U32 const endIndex = (U32)(streamPtr->end - streamPtr->prefixStart) + streamPtr->dictLimit;
streamPtr->end = (const BYTE*)safeBuffer + dictSize;
streamPtr->prefixStart = streamPtr->end - dictSize;
@@ -1587,7 +1587,7 @@ _last_literals:
} else {
*op++ = (BYTE)(lastRunSize << ML_BITS);
}
- memcpy(op, anchor, lastRunSize);
+ LZ4_memcpy(op, anchor, lastRunSize);
op += lastRunSize;
}