From: Dmitry-Me Date: Mon, 15 Feb 2016 07:12:40 +0000 (+0300) Subject: GH680: Reuse strnlen() in strndup() X-Git-Tag: OpenSSL_1_1_0-pre4~497 X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=commitdiff_plain;h=d3c02d844abeaf961bad692cf6f3876ccabf2435 GH680: Reuse strnlen() in strndup() Signed-off-by: Rich Salz Reviewed-by: Matt Caswell --- diff --git a/crypto/o_str.c b/crypto/o_str.c index b200060917..b01128cdb3 100644 --- a/crypto/o_str.c +++ b/crypto/o_str.c @@ -133,17 +133,13 @@ char *CRYPTO_strdup(const char *str, const char* file, int line) char *CRYPTO_strndup(const char *str, size_t s, const char* file, int line) { - const char *cp; size_t maxlen; char *ret; if (str == NULL) return NULL; - /* Get length. */ - for (cp = str, maxlen = s; maxlen-- != 0 && *cp != '\0'; ++cp) - continue; - maxlen = cp - str; + maxlen = OPENSSL_strnlen(str, s) ret = CRYPTO_malloc(maxlen + 1, file, line); if (ret) {