Commit Graph

375 Commits

Author SHA1 Message Date
Takayuki Matsuoka
0fc36f1bc7 Suppress false positive warning from MSVC
MSVC (17.3 or earlier) reports the following warning

lz4\lib\lz4.c(527): warning C6385: Reading invalid data from 'v'.
Line 527 is : LZ4_memcpy(&v[4], v, 4);

But, obviously v[0..3] is always filled with meaningful value.
Therefore, this warning report is wrong.

We must revisit this issue with future version of MSVC.
2022-08-12 23:49:22 +09:00
Takayuki Matsuoka
67c321935b Fix document for LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION in lz4.c 2022-08-11 16:13:24 +09:00
Yann Collet
dee9f95fd9
Merge pull request #1129 from t-mat/disable-memory-alloc-add-doc
Add document for LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION
2022-08-10 10:59:36 -07:00
Takayuki Matsuoka
721e76d1af Add LZ4_FREESTANDING 2022-08-07 19:06:37 +09:00
Takayuki Matsuoka
d9e0741aee Add: Doxygen comment for LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION 2022-08-06 19:45:13 +09:00
Yann Collet
ca26930a91
Merge pull request #1124 from t-mat/compile-time-purge-memalloc-func
Introduce LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION
2022-08-05 21:36:57 +02:00
Yann Collet
ccd92cb43b simplify read_variable_length()
single sumtype return value
2022-08-03 02:57:26 +02:00
Yann Collet
63e9a62249 refactor read_variable_length()
updated documentation, more assert(),
overflow detection in 32-bit mode
2022-08-02 15:56:05 +02:00
Yann Collet
7d7cddfac1 remove support of decompress_fast*() from decompress_generic()
since it's now supported by decompress_unsafe().

The goal is to improve maintenability of decompress_generic()
by reducing its complexity.
2022-08-02 14:40:24 +02:00
Yann Collet
efd123e1f1 introduce LZ4_decompress_unsafe_generic()
designed to support specifically LZ4_decompress_fast*() variants.

The end goal is to offload this support from LZ4_decompress_generic
to improve its maintenance.
2022-08-02 12:53:22 +02:00
Takayuki Matsuoka
9173ca37d7 Fix : Internal memory allocation macro names 2022-08-01 06:12:45 +09:00
Dominique Pelle
3347485307 fix: various typos 2022-07-31 17:47:00 +02:00
Takayuki Matsuoka
fa889cf6da Introduce LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION
This changeset introduces new compile time switch macro LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION
which removes the following functions when it's defined.

```
// lz4.c
LZ4_createStream
LZ4_freeStream
LZ4_createStreamDecode
LZ4_freeStreamDecode
LZ4_create              // legacy

// lz4hc.c
LZ4_createStreamHC(void)
LZ4_freeStreamHC
LZ4_createHC            // legacy
LZ4_freeHC              // legacy
```

These functions uses dynamic memory allocation functions such as malloc() and free().
It'll be useful for freestanding environment which doesn't have these allocation functions.

Since this change breaks API, this macro is only valid with lz4 as a static linked object.
2022-07-31 21:10:55 +09:00
Takayuki Matsuoka
5d80375ded New macro for memcpy, memmove and memset
This changeset introduces the following external macros.

- Add new macro LZ4_memset() which enables to inject external function as memset().
- Similar macro LZ4_memmove() for memmove().
- In same manner, LZ4_memcpy() also can be overriden by external macro.
2022-07-31 20:59:09 +09:00
Yann Collet
d174f975d2 clarify static sizes of states for static allocation 2022-07-12 21:28:12 +02:00
Yann Collet
6fb713358b silence a useless MSVC warning 2022-07-04 14:29:35 -07:00
Qi Wang
b1e84b38ef API: add LZ4_decompress_safe_partial_usingDict API
feature request: #1051

Signed-off-by: Qi Wang <wangqi@linux.alibaba.com>
2022-06-07 17:12:19 +08:00
Yann Collet
379c1a10ca Introduce MIN and MAX bounds to LZ4_MEMORY_USAGE
ensure that `frametest` works fine with these values,
notably with low LZ4_MEMORY_USAGE (dict test notably)

following suggestions from @t-mat at #1016
2022-01-30 23:02:55 -08:00
Yann Collet
77bef09693 renamed unaligned -> LZ4_unaligned
better name space isolation
suggested by @boris-kolpackov in #1053
2022-01-28 21:24:12 -08:00
Ben Niu
c2d00cb97b
Add comments 2022-01-27 11:04:06 -08:00
Ben Niu
bee421b93d
Disable _tzcnt_u64 for ARM64EC
The ARM64EC is a new Microsoft-designed ARM64 ABI that is compatible with AMD64 code. However, not all AMD64 intrinsic functions are supported. For, intrinsics that are lowered to AVX, AVX2 and AVX512 instructions are not supported, including the _tzcnt_u64. To make sure this file compiles for ARM64EC, the use of _tzcnt_u64 should be neutered.
2022-01-26 18:02:31 -08:00
Arseny Kapoulkine
22e232dada Enable fast decoding on Apple/AArch64 builds
This makes decoding significantly faster on M1; measured on compressed source
code across 8 hardware threads, decompressing 294 MB to 1301 MB takes 513 ms
of cumulative work (2.53 GB/s) before, and 406 ms (3.2 GB/s) after this change
on M1 Pro.

There's no way to check if the target architecture is M1 specifically but the
gains are likely to be similar on recent iterations on Apple processors, and
the original performance issue was probably more specific to Qualcomm.
2021-11-22 11:23:41 -08:00
Zeyi (Rice) Fan
1a2e8f4e30 fix clang-cl _tzcnt_u64 not defined issue 2021-08-09 11:30:02 -07:00
Gabe Jones
b3d46ae07f Cast ALLOC return value to satisfy C++ 2021-06-15 12:09:14 -05:00
Yann Collet
dfc431fb3d fix NULL ptr arithmetic at lz4:2299 2021-05-28 01:10:41 -07:00
Yann Collet
539c783c98 fix NULL ptr arithmetic in lz4:1680
only do arithmetic if offset > 0
2021-05-28 01:08:18 -07:00
Yann Collet
59273b7127 fix UB lz4:988 and lz4:1178
ensure `dictBase` is only used
when there is an actual dictionary content.
2021-05-28 00:56:26 -07:00
Yann Collet
c2c0c47d5f fix NULL ptr arithmetic of lz4:1572
was blindly adding an offset (0) to `dictionary` which could be `NULL`.
2021-05-27 23:20:28 -07:00
Jasper Lievisse Adriaanse
8301a21773 Fix potential memory corruption with negative memmove() size 2021-02-26 15:21:20 +01:00
Thomas Waldmann
909aae8260 fix some typos (work by Andrea Gelmini) 2021-01-07 18:39:57 +01:00
Yann Collet
50ff8b3ae8 fix minor header date 2020-11-30 18:16:00 -08:00
Yann Collet
e0f85f2fc8 better visual conformance
only include <intrin.h> on vs2005+ (#947)
remove some useless #pragma
fix a few minor Visual warnings
2020-11-14 16:27:57 -08:00
Yann Collet
581c459b4e restrict BitScanForward() to VS2005+
suggested by @aqrit in #947
2020-11-14 14:26:08 -08:00
Yann Collet
a296839802 changed LZ4_calloc() to a 2-arguments signature
to remain similar to stdlib's calloc().

Updated test to use c++ compiler for stricter signature check.
2020-11-09 08:44:26 -08:00
Yann Collet
44b13db532 Merge branch 'dev' into customMem 2020-11-08 23:26:19 -08:00
Yann Collet
52646e8d75 first proposal for LZ4_USER_MEMORY_FUNCTIONS
makes it possible to replace at link time
malloc, calloc and free
by user-provided functions
which must be named LZ4_malloc(), LZ4_calloc() and LZ4_free().

answer #937
2020-11-08 21:17:32 -08:00
Yann Collet
9cf3f106a8
Merge pull request #944 from lz4/fix874
fix #874
2020-11-08 20:48:20 -08:00
Yann Collet
2a2b10f192 fixed remaining ubsan warnings 2020-11-08 18:08:43 -08:00
Yann Collet
2964b8a6f6 fix #874
coverity reported a warning regarding a memcpy() overwrite.
This is a false positive (the memory area is large enough),
but it's true that it's not trivial to determine (encompassing struct),
and it's proper anyway to only memcpy() just the right amount of data.
2020-11-08 13:21:58 -08:00
Yann Collet
e251a84025 fix minor UBs
- check alignment before casting a pointer
- saveDict : don't memmove() on NULL dst
2020-11-07 19:42:57 -08:00
Yann Collet
1d02141bf8
Merge pull request #941 from lz4/revertinline
Revert "Replace "static" to "LZ4_FORCE_INLINE" for small functions"
2020-11-07 17:18:04 -08:00
Yann Collet
f61eeb7793 Revert "Replace "static" to "LZ4_FORCE_INLINE" for small functions"
This reverts commit 0e3933edd4.
2020-11-07 11:02:30 -08:00
Yann Collet
d4bfcf8489 fix #935
minor: identical declaration and prototypes of `LZ4HC_compress_optimal()`

also :
very minor optimization of `LZ4_memcpy_using_offset()`
2020-11-07 10:06:52 -08:00
Yann Collet
b5e2a4acd9
Merge pull request #936 from lz4/alignTest
More alignment tests
2020-11-06 20:27:42 -08:00
Yann Collet
211d653ff8 re-enable alignment test on all targets 2020-11-06 16:43:14 -08:00
Yann Collet
e968a24129 unified alignment test
across lz4.c and lz4hc.c
2020-11-06 14:46:48 -08:00
remittor
0e3933edd4 Replace "static" to "LZ4_FORCE_INLINE" for small functions
The "static" specifier does not guarantee that the function will be inlined.
2020-10-07 09:52:40 +03:00
remittor
749bd91a06 Replace define LZ4_FORCE_O2_INLINE_GCC_PPC64LE to LZ4_FORCE_INLINE
There is no reason to separate these two definitions!
2020-10-07 09:51:08 +03:00
remittor
c4792cdfa9 Fix: The "inline" specifier do not use for LZ4_wildCopy8 and LZ4_wildCopy32
This problem was reproduced on MSVC 2015 (32-bit). Both functions were called using the operator "call".
2020-10-06 17:16:43 +03:00
Yann Collet
7d21f761c3 fix conversion warning 2020-09-29 21:53:42 -07:00