+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]
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}