summaryrefslogtreecommitdiffstats
path: root/Utilities/cmliblzma/liblzma/simple/simple_coder.c
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-04-22 19:39:58 (GMT)
committerBrad King <brad.king@kitware.com>2021-04-22 19:39:58 (GMT)
commite9065e96dc80ee62fa9bf9df559d0d8e6d8e0117 (patch)
tree108f8ef033665a2d5686004e3f8a6e2a1db3254e /Utilities/cmliblzma/liblzma/simple/simple_coder.c
parent741b85b42b4c8d826634b3f968d7de21df5f6c85 (diff)
parentee909a8e8b785b68c6a14fd52cc12b1841051a7d (diff)
downloadCMake-e9065e96dc80ee62fa9bf9df559d0d8e6d8e0117.zip
CMake-e9065e96dc80ee62fa9bf9df559d0d8e6d8e0117.tar.gz
CMake-e9065e96dc80ee62fa9bf9df559d0d8e6d8e0117.tar.bz2
Merge branch 'upstream-liblzma' into lzma-threads
* upstream-liblzma: liblzma 2020-03-17 (2327a461)
Diffstat (limited to 'Utilities/cmliblzma/liblzma/simple/simple_coder.c')
-rw-r--r--Utilities/cmliblzma/liblzma/simple/simple_coder.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/Utilities/cmliblzma/liblzma/simple/simple_coder.c b/Utilities/cmliblzma/liblzma/simple/simple_coder.c
index 13ebabc..4f499be 100644
--- a/Utilities/cmliblzma/liblzma/simple/simple_coder.c
+++ b/Utilities/cmliblzma/liblzma/simple/simple_coder.c
@@ -118,7 +118,15 @@ simple_code(void *coder_ptr, const lzma_allocator *allocator,
// coder->pos and coder->size yet. This way the coder can be
// restarted if the next filter in the chain returns e.g.
// LZMA_MEM_ERROR.
- memcpy(out + *out_pos, coder->buffer + coder->pos, buf_avail);
+ //
+ // Do the memcpy() conditionally because out can be NULL
+ // (in which case buf_avail is always 0). Calling memcpy()
+ // with a null-pointer is undefined even if the third
+ // argument is 0.
+ if (buf_avail > 0)
+ memcpy(out + *out_pos, coder->buffer + coder->pos,
+ buf_avail);
+
*out_pos += buf_avail;
// Copy/Encode/Decode more data to out[].