Re: [PATCH v3 1/2] Fix nonnull errors reported by UBSAN with GCC 7.
- From
Johannes Sixt <j6t@kdbg.org>
- Date
- Apr 17, 2017, 07:59 UTC
- Message-ID
- <930be745-944f-62f3-3d57-4f1cd6f2df66@kdbg.org>
- In-Reply-To
- <xmqqy3uzkdm4.fsf@gitster.mtv.corp.google.com>
Am 17.04.2017 um 03:49 schrieb Junio C Hamano:
Show 6 quoted lines
> "Something or NULL" is a name we use for a function that returns > something (under normal circumstances) or returns NULL. This > wrapper is not about returning NULL at all, as far as I can see, and > is misnamed. If it is about "avoid moving 0 bytes", similar to how > COPY_ARRAY() is used in the previous hunk, perhaps MOVE_ARRAY() is a > better name?
It is not about "avoid moving 0 bytes", but "if we move 0 bytes, then we allow NULL pointers". Plain memmove/memcpy do not allow the pointers to be NULL even if the count is 0. It just so happens that the implementation of memmove_or_null that permits the relaxed condition looks like "avoid moving 0 bytes".
The name was my suggestion, but I agree that it is not the best name. [Sentence about two most difficult things in software engineering omitted for brevity.]
-- Hannes