mirror of
https://git.tukaani.org/xz.git
synced 2024-04-04 12:36:23 +02:00
596ed3de44
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. |
||
---|---|---|
.. | ||
lz_decoder.c | ||
lz_decoder.h | ||
lz_encoder.c | ||
lz_encoder.h | ||
lz_encoder_hash.h | ||
lz_encoder_hash_table.h | ||
lz_encoder_mf.c | ||
Makefile.inc |