Re: [PATCH v3 1/2] Fix nonnull errors reported by UBSAN with GCC 7.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 06.04.2017 um 18:33 schrieb Johannes Sixt:
Am 06.04.2017 um 17:42 schrieb Martin Liška:
+static inline void *sane_memmove(void *dest, const void *src, size_t n)
+{
+    if (n > 0)
+        return memmove(dest, src, n);
+    else
+        return dest;
+}

Huh? memmove with n == 0 is well-defined. This wrapper is pointless.

memmove(3) with NULL pointers is undefined.  From string.h on Debian:

  extern void *memmove (void *__dest, const void *__src, size_t __n)
       __THROW __nonnull ((1, 2));

Sometimes we use a NULL pointer and a size of zero to represent arrays with no members. That convention is incompatible with memmove(3), but the wrapper above would support it. Checking the size instead of the pointer is preferable because a positive length with NULL pointers should still result in a segfault instead of a silent no-op.

(I'd still prefer a MOVE_ARRAY macro which also infers the element
size).

René



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]