diff options
Diffstat (limited to 'debug/stpcpy_chk.c')
-rw-r--r-- | debug/stpcpy_chk.c | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/debug/stpcpy_chk.c b/debug/stpcpy_chk.c index 91c50316ec..7cc4a21516 100644 --- a/debug/stpcpy_chk.c +++ b/debug/stpcpy_chk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992-2015 Free Software Foundation, Inc. +/* Copyright (C) 1992-2016 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -24,21 +24,11 @@ /* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */ char * -__stpcpy_chk (dest, src, destlen) - char *dest; - const char *src; - size_t destlen; +__stpcpy_chk (char *dest, const char *src, size_t destlen) { - char *d = dest; - const char *s = src; - - do - { - if (__glibc_unlikely (destlen-- == 0)) - __chk_fail (); - *d++ = *s; - } - while (*s++ != '\0'); - - return d - 1; + size_t len = strlen (src); + if (len >= destlen) + __chk_fail (); + + return memcpy (dest, src, len + 1) + len; } |