This change also avoids calling strlen twice when srclen is 0
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
{
void *tmp;
if (src) {
- if (srclen == 0) {
- tmp = OPENSSL_strdup(src);
+ if (srclen == 0)
srclen = strlen(src);
- } else
- tmp = OPENSSL_memdup(src, srclen);
- if (!tmp)
+
+ tmp = OPENSSL_memdup(src, srclen);
+ if (tmp == NULL)
return 0;
} else {
tmp = NULL;
}
OPENSSL_free(*pdest);
*pdest = tmp;
- if (pdestlen)
+ if (pdestlen != NULL)
*pdestlen = srclen;
return 1;
}