public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [libmpx, committed] Add zero length check for memmove wrapper
@ 2015-04-09 10:12 Ilya Enkovich
  0 siblings, 0 replies; only message in thread
From: Ilya Enkovich @ 2015-04-09 10:12 UTC (permalink / raw)
  To: gcc-patches

Hi,

This patch adds a zero length check into memmove wrapper (also affecting memcpy and mempcpy) to avoid unnecessary bounds checks.  Tested on on x86_64-unknown-linux-gnu.  Applied to trunk.

Thanks,
Ilya
--
libmpx/

2015-04-09  Ilya Enkovich  <ilya.enkovich@intel.com>

	* mpxwrap/mpx_wrappers.c (__mpx_wrapper_memmove): Add
	zero length check.

gcc/testsuite/

2015-04-09  Ilya Enkovich  <ilya.enkovich@intel.com>

	* gcc.target/i386/mpx/memmove-zero-length.c: New.


diff --git a/gcc/testsuite/gcc.target/i386/mpx/memmove-zero-length.c b/gcc/testsuite/gcc.target/i386/mpx/memmove-zero-length.c
new file mode 100644
index 0000000..78bfdeb
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/mpx/memmove-zero-length.c
@@ -0,0 +1,18 @@
+/* { dg-do run } */
+/* { dg-options "-fcheck-pointer-bounds -mmpx" } */
+
+
+#include "mpx-check.h"
+#include "string.h"
+
+int mpx_test (int argc, const char **argv)
+{
+  int *buf = (int *)malloc (100 * sizeof(int));
+
+  memmove (buf, NULL, 0);
+  memmove (NULL, buf, 0);
+
+  free (buf);
+
+  return 0;
+}
diff --git a/libmpx/mpxwrap/mpx_wrappers.c b/libmpx/mpxwrap/mpx_wrappers.c
index ef4be8d..58670aa 100644
--- a/libmpx/mpxwrap/mpx_wrappers.c
+++ b/libmpx/mpxwrap/mpx_wrappers.c
@@ -97,6 +97,9 @@ __mpx_wrapper_memmove (void *dst, const void *src, size_t n)
   size_t offset_src = ((size_t) s) & (sizeof (void *) - 1);
   size_t offset_dst = ((size_t) d) & (sizeof (void *) - 1);
 
+  if (n == 0)
+    return ret;
+
   __bnd_chk_ptr_bounds (dst, n);
   __bnd_chk_ptr_bounds (src, n);
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-04-09 10:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-09 10:12 [libmpx, committed] Add zero length check for memmove wrapper Ilya Enkovich

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).