unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#19213: 25.0.50; [PATCH] * editfns.c (Ftranspose_regions): memmove instead of memcpy
@ 2014-11-28 20:26 Fredrik Bergroth
  2016-02-23 11:41 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Fredrik Bergroth @ 2014-11-28 20:26 UTC (permalink / raw)
  To: 19213

In one case, `memcpy' is used 4 times to transform [r1|mid|r2] into
[r2|mid|r1], but `dest' and `src' may overlap when copying the mid
interval, which is forbidden by `memcpy' and results in undefined
behavior. Instead use `memmove' like other cases do.
---
 src/editfns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/editfns.c b/src/editfns.c
index 0a07886..82bd26d 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -4898,7 +4898,7 @@ Transposing beyond buffer boundaries is an error.  */)
 	  start2_addr = BYTE_POS_ADDR (start2_byte);
           memcpy (temp, start1_addr, len1_byte);
           memcpy (start1_addr, start2_addr, len2_byte);
-          memcpy (start1_addr + len2_byte, start1_addr + len1_byte, len_mid);
+          memmove (start1_addr + len2_byte, start1_addr + len1_byte, len_mid);
           memcpy (start1_addr + len2_byte + len_mid, temp, len1_byte);
 	  SAFE_FREE ();

--
1.9.1





^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#19213: 25.0.50; [PATCH] * editfns.c (Ftranspose_regions): memmove instead of memcpy
  2014-11-28 20:26 bug#19213: 25.0.50; [PATCH] * editfns.c (Ftranspose_regions): memmove instead of memcpy Fredrik Bergroth
@ 2016-02-23 11:41 ` Lars Ingebrigtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-23 11:41 UTC (permalink / raw)
  To: Fredrik Bergroth; +Cc: 19213

Fredrik Bergroth <fbergroth@gmail.com> writes:

> In one case, `memcpy' is used 4 times to transform [r1|mid|r2] into
> [r2|mid|r1], but `dest' and `src' may overlap when copying the mid
> interval, which is forbidden by `memcpy' and results in undefined
> behavior. Instead use `memmove' like other cases do.
> ---
>  src/editfns.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/editfns.c b/src/editfns.c
> index 0a07886..82bd26d 100644
> --- a/src/editfns.c
> +++ b/src/editfns.c
> @@ -4898,7 +4898,7 @@ Transposing beyond buffer boundaries is an error.  */)
>  	  start2_addr = BYTE_POS_ADDR (start2_byte);
>            memcpy (temp, start1_addr, len1_byte);
>            memcpy (start1_addr, start2_addr, len2_byte);
> -          memcpy (start1_addr + len2_byte, start1_addr + len1_byte, len_mid);
> +          memmove (start1_addr + len2_byte, start1_addr + len1_byte, len_mid);

Thanks; applied to the Emacs trunk.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-02-23 11:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-28 20:26 bug#19213: 25.0.50; [PATCH] * editfns.c (Ftranspose_regions): memmove instead of memcpy Fredrik Bergroth
2016-02-23 11:41 ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).