Implement BUF_strnlen() and use it instead of strlen().

This commit is contained in:
Ben Laurie 2014-05-21 11:54:54 +01:00
parent 397a8e747d
commit dea4a18404
2 changed files with 12 additions and 1 deletions

View File

@ -62,6 +62,16 @@
#include "cryptlib.h"
#include <openssl/buffer.h>
size_t BUF_strnlen(const char *str, size_t maxlen)
{
const char *p;
for (p = str; *p != '\0' && maxlen-- != 0; ++p)
;
return p - str;
}
char *BUF_strdup(const char *str)
{
if (str == NULL) return(NULL);
@ -75,7 +85,7 @@ char *BUF_strndup(const char *str, size_t siz)
if (str == NULL) return(NULL);
len = strlen(str);
len = BUF_strnlen(str, siz);
if (siz > len)
siz = len;

View File

@ -85,6 +85,7 @@ BUF_MEM *BUF_MEM_new(void);
void BUF_MEM_free(BUF_MEM *a);
int BUF_MEM_grow(BUF_MEM *str, size_t len);
int BUF_MEM_grow_clean(BUF_MEM *str, size_t len);
size_t BUF_strnlen(const char *str, size_t maxlen);
char * BUF_strdup(const char *str);
char * BUF_strndup(const char *str, size_t siz);
void * BUF_memdup(const void *data, size_t siz);