git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
René Scharfe <l.s.r@web.de>
Date
Apr 6, 2017, 17:31 UTC
Message-ID
<e392e05c-2815-8cfa-eed0-bd990f8ce954@web.de>
In-Reply-To
<587b0cb9-bd66-ddf7-5cca-023df3470883@kdbg.org>
Am 06.04.2017 um 18:33 schrieb Johannes Sixt:
Show 10 quoted lines
> 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é
Previous: Johannes SixtNext: Johannes Sixt
Message 7 of 15 in “Fix nonnull errors reported by UBSAN with GCC 7.”
  1. 1/2 Fix nonnull errors reported by UBSAN with GCC 7.Martin Liška, Apr 6, 2017
  2. Jeff KingApr 6, 2017
  3. Martin LiškaApr 6, 2017
  4. René ScharfeApr 6, 2017
  5. Martin LiškaApr 6, 2017
  6. Johannes SixtApr 6, 2017
  7. René ScharfeApr 6, 2017
  8. Johannes SixtApr 6, 2017
  9. Martin LiškaApr 7, 2017
  10. René ScharfeApr 7, 2017
  11. 1/2 add MOVE_ARRAYRené Scharfe, Apr 7, 2017
  12. 2/2 use MOVE_ARRAYRené Scharfe, Apr 7, 2017
  13. Junio C HamanoApr 17, 2017
  14. Johannes SixtApr 17, 2017
  15. Johannes SchindelinApr 6, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.