]> sourceware.org Git - glibc.git/commitdiff
Refactor several debug routines.
authorOndřej Bílka <neleai@seznam.cz>
Wed, 4 Dec 2013 01:02:25 +0000 (02:02 +0100)
committerOndřej Bílka <neleai@seznam.cz>
Wed, 4 Dec 2013 01:41:12 +0000 (02:41 +0100)
To simplify additions of debug routines we replace a custom function
implementation by a simple call.

ChangeLog
debug/memcpy_chk.c
debug/memmove_chk.c
debug/mempcpy_chk.c
debug/memset_chk.c
debug/stpncpy_chk.c
debug/strncpy_chk.c

index de64f3f71bd3de89b631db2c0b6c917a6010fbe1..6320d1969e92fe33d54aced28e9dfa088f3cde76 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2013-12-04  Ondřej Bílka  <neleai@seznam.cz>
+
+       * debug/memcpy_chk.c (__memcpy_chk): Use call instead of custom
+       implementation.
+       * debug/memmove_chk.c (MEMMOVE_CHK): Likewise.
+       * debug/mempcpy_chk.c (__mempcpy_chk): Likewise.
+       * debug/memset_chk.c (__memset_chk): Likewise.
+       * debug/stpncpy_chk.c (__stpncpy_chk): Likewise.
+       * debug/strncpy_chk.c: Likewise.
+
 2013-12-03  Joseph Myers  <joseph@codesourcery.com>
 
        [BZ #15268]
index a53dd7642b67c252f264d29b72acc80498c9b109..5bbc44f57adcf1ba05d4f384477702517aea9497 100644 (file)
@@ -32,34 +32,5 @@ __memcpy_chk (dstpp, srcpp, len, dstlen)
   if (__builtin_expect (dstlen < len, 0))
     __chk_fail ();
 
-  unsigned long int dstp = (long int) dstpp;
-  unsigned long int srcp = (long int) srcpp;
-
-  /* Copy from the beginning to the end.  */
-
-  /* If there not too few bytes to copy, use word copy.  */
-  if (len >= OP_T_THRES)
-    {
-      /* Copy just a few bytes to make DSTP aligned.  */
-      len -= (-dstp) % OPSIZ;
-      BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ);
-
-      /* Copy whole pages from SRCP to DSTP by virtual address manipulation,
-        as much as possible.  */
-
-      PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len);
-
-      /* Copy from SRCP to DSTP taking advantage of the known alignment of
-        DSTP.  Number of bytes remaining is put in the third argument,
-        i.e. in LEN.  This number may vary from machine to machine.  */
-
-      WORD_COPY_FWD (dstp, srcp, len, len);
-
-      /* Fall out and copy the tail.  */
-    }
-
-  /* There are just a few bytes to copy.  Use byte memory operations.  */
-  BYTE_COPY_FWD (dstp, srcp, len);
-
-  return dstpp;
+  return memcpy (dstpp, srcpp, len);
 }
index 3ea34c6d04721235645c12b632c36c164c0d9f0f..6337e76ec2dc225d0076ce13d1e6886c21e61d39 100644 (file)
@@ -36,66 +36,5 @@ MEMMOVE_CHK (dest, src, len, destlen)
   if (__builtin_expect (destlen < len, 0))
     __chk_fail ();
 
-  unsigned long int dstp = (long int) dest;
-  unsigned long int srcp = (long int) src;
-
-  /* This test makes the forward copying code be used whenever possible.
-     Reduces the working set.  */
-  if (dstp - srcp >= len)      /* *Unsigned* compare!  */
-    {
-      /* Copy from the beginning to the end.  */
-
-      /* If there not too few bytes to copy, use word copy.  */
-      if (len >= OP_T_THRES)
-       {
-         /* Copy just a few bytes to make DSTP aligned.  */
-         len -= (-dstp) % OPSIZ;
-         BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ);
-
-         /* Copy whole pages from SRCP to DSTP by virtual address
-            manipulation, as much as possible.  */
-
-         PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len);
-
-         /* Copy from SRCP to DSTP taking advantage of the known
-            alignment of DSTP.  Number of bytes remaining is put
-            in the third argument, i.e. in LEN.  This number may
-            vary from machine to machine.  */
-
-         WORD_COPY_FWD (dstp, srcp, len, len);
-
-         /* Fall out and copy the tail.  */
-       }
-
-      /* There are just a few bytes to copy.  Use byte memory operations.  */
-      BYTE_COPY_FWD (dstp, srcp, len);
-    }
-  else
-    {
-      /* Copy from the end to the beginning.  */
-      srcp += len;
-      dstp += len;
-
-      /* If there not too few bytes to copy, use word copy.  */
-      if (len >= OP_T_THRES)
-       {
-         /* Copy just a few bytes to make DSTP aligned.  */
-         len -= dstp % OPSIZ;
-         BYTE_COPY_BWD (dstp, srcp, dstp % OPSIZ);
-
-         /* Copy from SRCP to DSTP taking advantage of the known
-            alignment of DSTP.  Number of bytes remaining is put
-            in the third argument, i.e. in LEN.  This number may
-            vary from machine to machine.  */
-
-         WORD_COPY_BWD (dstp, srcp, len, len);
-
-         /* Fall out and copy the tail.  */
-       }
-
-      /* There are just a few bytes to copy.  Use byte memory operations.  */
-      BYTE_COPY_BWD (dstp, srcp, len);
-    }
-
-  return dest;
+  return memmove (dest, src, len);
 }
index 689588384140a0c05d5be0f95c91d552957df20e..1573a29d02b05b61cb036f4b92cf8e021a2d371c 100644 (file)
@@ -33,34 +33,5 @@ __mempcpy_chk (dstpp, srcpp, len, dstlen)
   if (__builtin_expect (dstlen < len, 0))
     __chk_fail ();
 
-  unsigned long int dstp = (long int) dstpp;
-  unsigned long int srcp = (long int) srcpp;
-
-  /* Copy from the beginning to the end.  */
-
-  /* If there not too few bytes to copy, use word copy.  */
-  if (len >= OP_T_THRES)
-    {
-      /* Copy just a few bytes to make DSTP aligned.  */
-      len -= (-dstp) % OPSIZ;
-      BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ);
-
-      /* Copy whole pages from SRCP to DSTP by virtual address manipulation,
-        as much as possible.  */
-
-      PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len);
-
-      /* Copy from SRCP to DSTP taking advantage of the known alignment of
-        DSTP.  Number of bytes remaining is put in the third argument,
-        i.e. in LEN.  This number may vary from machine to machine.  */
-
-      WORD_COPY_FWD (dstp, srcp, len, len);
-
-      /* Fall out and copy the tail.  */
-    }
-
-  /* There are just a few bytes to copy.  Use byte memory operations.  */
-  BYTE_COPY_FWD (dstp, srcp, len);
-
-  return (void *) dstp;
+  return __mempcpy (dstpp, srcpp, len);
 }
index bfbc29d29408159e63704f219d0a5073193e432b..ef1cadb60fb3dffe6a9b41d5376405c99452037c 100644 (file)
@@ -28,64 +28,5 @@ __memset_chk (dstpp, c, len, dstlen)
   if (__builtin_expect (dstlen < len, 0))
     __chk_fail ();
 
-  long int dstp = (long int) dstpp;
-
-  if (len >= 8)
-    {
-      size_t xlen;
-      op_t cccc;
-
-      cccc = (unsigned char) c;
-      cccc |= cccc << 8;
-      cccc |= cccc << 16;
-      if (OPSIZ > 4)
-       /* Do the shift in two steps to avoid warning if long has 32 bits.  */
-       cccc |= (cccc << 16) << 16;
-
-      /* There are at least some bytes to set.
-        No need to test for LEN == 0 in this alignment loop.  */
-      while (dstp % OPSIZ != 0)
-       {
-         ((byte *) dstp)[0] = c;
-         dstp += 1;
-         len -= 1;
-       }
-
-      /* Write 8 `op_t' per iteration until less than 8 `op_t' remain.  */
-      xlen = len / (OPSIZ * 8);
-      while (xlen > 0)
-       {
-         ((op_t *) dstp)[0] = cccc;
-         ((op_t *) dstp)[1] = cccc;
-         ((op_t *) dstp)[2] = cccc;
-         ((op_t *) dstp)[3] = cccc;
-         ((op_t *) dstp)[4] = cccc;
-         ((op_t *) dstp)[5] = cccc;
-         ((op_t *) dstp)[6] = cccc;
-         ((op_t *) dstp)[7] = cccc;
-         dstp += 8 * OPSIZ;
-         xlen -= 1;
-       }
-      len %= OPSIZ * 8;
-
-      /* Write 1 `op_t' per iteration until less than OPSIZ bytes remain.  */
-      xlen = len / OPSIZ;
-      while (xlen > 0)
-       {
-         ((op_t *) dstp)[0] = cccc;
-         dstp += OPSIZ;
-         xlen -= 1;
-       }
-      len %= OPSIZ;
-    }
-
-  /* Write the last few bytes.  */
-  while (len > 0)
-    {
-      ((byte *) dstp)[0] = c;
-      dstp += 1;
-      len -= 1;
-    }
-
-  return dstpp;
+  return memset (dstpp, c, len);
 }
index 35a2c23508339c3281a0c9c6ed4d6cf659a09010..f9fa66ccafb8582dc4a657ed58a32d22543cb2ee 100644 (file)
@@ -31,54 +31,5 @@ __stpncpy_chk (char *dest, const char *src, size_t n, size_t destlen)
   if (__builtin_expect (destlen < n, 0))
     __chk_fail ();
 
-  if (n >= 4)
-    {
-      size_t n4 = n >> 2;
-
-      for (;;)
-       {
-         c = *src++;
-         *dest++ = c;
-         if (c == '\0')
-           break;
-         c = *src++;
-         *dest++ = c;
-         if (c == '\0')
-           break;
-         c = *src++;
-         *dest++ = c;
-         if (c == '\0')
-           break;
-         c = *src++;
-         *dest++ = c;
-         if (c == '\0')
-           break;
-         if (--n4 == 0)
-           goto last_chars;
-       }
-      n -= dest - s;
-      goto zero_fill;
-    }
-
- last_chars:
-  n &= 3;
-  if (n == 0)
-    return dest;
-
-  for (;;)
-    {
-      c = *src++;
-      --n;
-      *dest++ = c;
-      if (c == '\0')
-       break;
-      if (n == 0)
-       return dest;
-    }
-
- zero_fill:
-  while (n-- > 0)
-    dest[n] = '\0';
-
-  return dest - 1;
+  return __stpncpy (dest, src, n);
 }
index d067bd9ac32d5a77af7afff41fca386c426c85c9..2e078b1e4f7935b5347d9aec88bbca9995fa5871 100644 (file)
@@ -26,63 +26,8 @@ __strncpy_chk (s1, s2, n, s1len)
      size_t n;
      size_t s1len;
 {
-  char c;
-  char *s = s1;
-
   if (__builtin_expect (s1len < n, 0))
     __chk_fail ();
 
-  --s1;
-
-  if (n >= 4)
-    {
-      size_t n4 = n >> 2;
-
-      for (;;)
-       {
-         c = *s2++;
-         *++s1 = c;
-         if (c == '\0')
-           break;
-         c = *s2++;
-         *++s1 = c;
-         if (c == '\0')
-           break;
-         c = *s2++;
-         *++s1 = c;
-         if (c == '\0')
-           break;
-         c = *s2++;
-         *++s1 = c;
-         if (c == '\0')
-           break;
-         if (--n4 == 0)
-           goto last_chars;
-       }
-      n = n - (s1 - s) - 1;
-      if (n == 0)
-       return s;
-      goto zero_fill;
-    }
-
- last_chars:
-  n &= 3;
-  if (n == 0)
-    return s;
-
-  do
-    {
-      c = *s2++;
-      *++s1 = c;
-      if (--n == 0)
-       return s;
-    }
-  while (c != '\0');
-
- zero_fill:
-  do
-    *++s1 = '\0';
-  while (--n > 0);
-
-  return s;
+  return strncpy (s1, s2, n);
 }
This page took 0.123865 seconds and 5 git commands to generate.