Implement BUF_strnlen() and use it instead of strlen().
This commit is contained in:
parent
397a8e747d
commit
dea4a18404
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user