1
0
Fork 0
mirror of https://git.tukaani.org/xz.git synced 2024-04-04 12:36:23 +02:00
xz-archive/src/liblzma/lz
Lasse Collin 596ed3de44 liblzma: Avoid memcpy(NULL, foo, 0) because it is undefined behavior.
I should have always known this but I didn't. Here is an example
as a reminder to myself:

    int mycopy(void *dest, void *src, size_t n)
    {
        memcpy(dest, src, n);
        return dest == NULL;
    }

In the example, a compiler may assume that dest != NULL because
passing NULL to memcpy() would be undefined behavior. Testing
with GCC 8.2.1, mycopy(NULL, NULL, 0) returns 1 with -O0 and -O1.
With -O2 the return value is 0 because the compiler infers that
dest cannot be NULL because it was already used with memcpy()
and thus the test for NULL gets optimized out.

In liblzma, if a null-pointer was passed to memcpy(), there were
no checks for NULL *after* the memcpy() call, so I cautiously
suspect that it shouldn't have caused bad behavior in practice,
but it's hard to be sure, and the problematic cases had to be
fixed anyway.

Thanks to Jeffrey Walton.
2019-07-13 17:56:28 +03:00
..
lz_decoder.c liblzma: Avoid memcpy(NULL, foo, 0) because it is undefined behavior. 2019-07-13 17:56:28 +03:00
lz_decoder.h liblzma: Avoid multiple definitions of lzma_coder structures. 2016-12-28 19:59:32 +02:00
lz_encoder.c liblzma: Avoid multiple definitions of lzma_coder structures. 2016-12-28 19:59:32 +02:00
lz_encoder.h liblzma: Avoid multiple definitions of lzma_coder structures. 2016-12-28 19:59:32 +02:00
lz_encoder_hash.h liblzma: Remove unneeded semicolon. 2011-06-16 12:15:29 +03:00
lz_encoder_hash_table.h Make liblzma produce the same output on both endiannesses. 2009-10-02 11:03:26 +03:00
lz_encoder_mf.c liblzma: Use lzma_memcmplen() in the BT3 match finder. 2014-08-04 19:25:58 +03:00
Makefile.inc Make liblzma produce the same output on both endiannesses. 2009-10-02 11:03:26 +03:00