From 1103accf69f1c89aa5088fb29c024092438e955a Mon Sep 17 00:00:00 2001 From: jsing Date: Sat, 26 Apr 2014 13:07:16 +0000 Subject: [PATCH] More KNF. --- lib/libcrypto/buffer/buf_str.c | 5 ++++- lib/libcrypto/buffer/buffer.c | 11 ++++++----- lib/libssl/src/crypto/buffer/buf_str.c | 5 ++++- lib/libssl/src/crypto/buffer/buffer.c | 11 ++++++----- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/libcrypto/buffer/buf_str.c b/lib/libcrypto/buffer/buf_str.c index 819155626a0..33836d0af4e 100644 --- a/lib/libcrypto/buffer/buf_str.c +++ b/lib/libcrypto/buffer/buf_str.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buf_str.c,v 1.7 2014/04/17 14:28:44 beck Exp $ */ +/* $OpenBSD: buf_str.c,v 1.8 2014/04/26 13:07:16 jsing Exp $ */ /* * Copyright (c) 2014 Bob Beck * @@ -31,6 +31,7 @@ char * BUF_strdup(const char *str) { char *ret = NULL; + if (str != NULL) { if (!(ret = strdup(str))) BUFerr(BUF_F_BUF_STRDUP, ERR_R_MALLOC_FAILURE); @@ -42,6 +43,7 @@ char * BUF_strndup(const char *str, size_t siz) { char *ret = NULL; + if (str != NULL) { if (!(ret = strndup(str, siz))) BUFerr(BUF_F_BUF_STRNDUP, ERR_R_MALLOC_FAILURE); @@ -53,6 +55,7 @@ void * BUF_memdup(const void *data, size_t siz) { void *ret = NULL; + if (data != NULL) { if (!(ret = malloc(siz))) BUFerr(BUF_F_BUF_MEMDUP, ERR_R_MALLOC_FAILURE); diff --git a/lib/libcrypto/buffer/buffer.c b/lib/libcrypto/buffer/buffer.c index a50c30a3485..486d6fef141 100644 --- a/lib/libcrypto/buffer/buffer.c +++ b/lib/libcrypto/buffer/buffer.c @@ -88,7 +88,7 @@ BUF_MEM_free(BUF_MEM *a) return; if (a->data != NULL) { - memset(a->data, 0,(unsigned int)a->max); + memset(a->data, 0, (unsigned int)a->max); free(a->data); } free(a); @@ -105,7 +105,7 @@ BUF_MEM_grow(BUF_MEM *str, size_t len) return (len); } if (str->max >= len) { - memset(&str->data[str->length], 0,len - str->length); + memset(&str->data[str->length], 0, len - str->length); str->length = len; return (len); } @@ -125,7 +125,7 @@ BUF_MEM_grow(BUF_MEM *str, size_t len) } else { str->data = ret; str->max = n; - memset(&str->data[str->length], 0,len - str->length); + memset(&str->data[str->length], 0, len - str->length); str->length = len; } return (len); @@ -138,12 +138,12 @@ BUF_MEM_grow_clean(BUF_MEM *str, size_t len) size_t n; if (str->length >= len) { - memset(&str->data[len], 0,str->length - len); + memset(&str->data[len], 0, str->length - len); str->length = len; return (len); } if (str->max >= len) { - memset(&str->data[str->length], 0,len - str->length); + memset(&str->data[str->length], 0, len - str->length); str->length = len; return (len); } @@ -176,6 +176,7 @@ void BUF_reverse(unsigned char *out, const unsigned char *in, size_t size) { size_t i; + if (in) { out += size - 1; for (i = 0; i < size; i++) diff --git a/lib/libssl/src/crypto/buffer/buf_str.c b/lib/libssl/src/crypto/buffer/buf_str.c index 819155626a0..33836d0af4e 100644 --- a/lib/libssl/src/crypto/buffer/buf_str.c +++ b/lib/libssl/src/crypto/buffer/buf_str.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buf_str.c,v 1.7 2014/04/17 14:28:44 beck Exp $ */ +/* $OpenBSD: buf_str.c,v 1.8 2014/04/26 13:07:16 jsing Exp $ */ /* * Copyright (c) 2014 Bob Beck * @@ -31,6 +31,7 @@ char * BUF_strdup(const char *str) { char *ret = NULL; + if (str != NULL) { if (!(ret = strdup(str))) BUFerr(BUF_F_BUF_STRDUP, ERR_R_MALLOC_FAILURE); @@ -42,6 +43,7 @@ char * BUF_strndup(const char *str, size_t siz) { char *ret = NULL; + if (str != NULL) { if (!(ret = strndup(str, siz))) BUFerr(BUF_F_BUF_STRNDUP, ERR_R_MALLOC_FAILURE); @@ -53,6 +55,7 @@ void * BUF_memdup(const void *data, size_t siz) { void *ret = NULL; + if (data != NULL) { if (!(ret = malloc(siz))) BUFerr(BUF_F_BUF_MEMDUP, ERR_R_MALLOC_FAILURE); diff --git a/lib/libssl/src/crypto/buffer/buffer.c b/lib/libssl/src/crypto/buffer/buffer.c index a50c30a3485..486d6fef141 100644 --- a/lib/libssl/src/crypto/buffer/buffer.c +++ b/lib/libssl/src/crypto/buffer/buffer.c @@ -88,7 +88,7 @@ BUF_MEM_free(BUF_MEM *a) return; if (a->data != NULL) { - memset(a->data, 0,(unsigned int)a->max); + memset(a->data, 0, (unsigned int)a->max); free(a->data); } free(a); @@ -105,7 +105,7 @@ BUF_MEM_grow(BUF_MEM *str, size_t len) return (len); } if (str->max >= len) { - memset(&str->data[str->length], 0,len - str->length); + memset(&str->data[str->length], 0, len - str->length); str->length = len; return (len); } @@ -125,7 +125,7 @@ BUF_MEM_grow(BUF_MEM *str, size_t len) } else { str->data = ret; str->max = n; - memset(&str->data[str->length], 0,len - str->length); + memset(&str->data[str->length], 0, len - str->length); str->length = len; } return (len); @@ -138,12 +138,12 @@ BUF_MEM_grow_clean(BUF_MEM *str, size_t len) size_t n; if (str->length >= len) { - memset(&str->data[len], 0,str->length - len); + memset(&str->data[len], 0, str->length - len); str->length = len; return (len); } if (str->max >= len) { - memset(&str->data[str->length], 0,len - str->length); + memset(&str->data[str->length], 0, len - str->length); str->length = len; return (len); } @@ -176,6 +176,7 @@ void BUF_reverse(unsigned char *out, const unsigned char *in, size_t size) { size_t i; + if (in) { out += size - 1; for (i = 0; i < size; i++) -- 2.20.1