From: Paul Eggert Date: Mon, 22 Mar 2021 01:08:13 +0000 (-0700) Subject: Fix replace-buffer-contents undefined behavior X-Git-Tag: emacs-28.0.90~3142^2 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=6a4ed891d8;p=emacs.git Fix replace-buffer-contents undefined behavior * src/editfns.c (Freplace_buffer_contents): Avoid undefined behavior with competing side effects in parallel subexpressions. Problem reported by Apple clang version 12.0.0 (clang-1200.0.32.29). --- diff --git a/src/editfns.c b/src/editfns.c index 621e35171d8..cd9633d4c6a 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -2053,6 +2053,8 @@ nil. */) code. */ ptrdiff_t del_bytes = (size_t) size_a / CHAR_BIT + 1; ptrdiff_t ins_bytes = (size_t) size_b / CHAR_BIT + 1; + unsigned char *deletions = SAFE_ALLOCA (del_bytes); + unsigned char *insertions = SAFE_ALLOCA (ins_bytes); struct context ctx = { .buffer_a = a, .buffer_b = b, @@ -2060,8 +2062,8 @@ nil. */) .beg_b = min_b, .a_unibyte = BUF_ZV (a) == BUF_ZV_BYTE (a), .b_unibyte = BUF_ZV (b) == BUF_ZV_BYTE (b), - .deletions = SAFE_ALLOCA (del_bytes), - .insertions = SAFE_ALLOCA (ins_bytes), + .deletions = deletions, + .insertions = insertions, .fdiag = buffer + size_b + 1, .bdiag = buffer + diags + size_b + 1, .heuristic = true,