diff --git a/STYLE.md b/STYLE.md index 17295b4f..a6aa3599 100644 --- a/STYLE.md +++ b/STYLE.md @@ -27,7 +27,9 @@ Google style guide do not apply. Support for C99 features depends on our target platforms. Typically, Chromium's target MSVC is the most restrictive. -Variable declarations in the middle of a function are allowed. +Variable declarations in the middle of a function or inside a `for` loop are +allowed and preferred where possible. Note that the common `goto err` cleanup +pattern requires lifting some variable declarations. Comments should be `/* C-style */` for consistency. diff --git a/crypto/mem.c b/crypto/mem.c index 527edd93..4596472a 100644 --- a/crypto/mem.c +++ b/crypto/mem.c @@ -83,8 +83,6 @@ OPENSSL_MSVC_PRAGMA(warning(pop)) void *OPENSSL_realloc_clean(void *ptr, size_t old_size, size_t new_size) { - void *ret = NULL; - if (ptr == NULL) { return OPENSSL_malloc(new_size); } @@ -99,7 +97,7 @@ void *OPENSSL_realloc_clean(void *ptr, size_t old_size, size_t new_size) { return NULL; } - ret = OPENSSL_malloc(new_size); + void *ret = OPENSSL_malloc(new_size); if (ret == NULL) { return NULL; } @@ -143,10 +141,9 @@ uint32_t OPENSSL_hash32(const void *ptr, size_t len) { static const uint32_t kOffsetBasis = 2166136261u; const uint8_t *in = ptr; - size_t i; uint32_t h = kOffsetBasis; - for (i = 0; i < len; i++) { + for (size_t i = 0; i < len; i++) { h ^= in[i]; h *= kPrime; } @@ -155,9 +152,7 @@ uint32_t OPENSSL_hash32(const void *ptr, size_t len) { } size_t OPENSSL_strnlen(const char *s, size_t len) { - size_t i; - - for (i = 0; i < len; i++) { + for (size_t i = 0; i < len; i++) { if (s[i] == 0) { return i; } @@ -194,12 +189,8 @@ int OPENSSL_strncasecmp(const char *a, const char *b, size_t n) { int BIO_snprintf(char *buf, size_t n, const char *format, ...) { va_list args; - int ret; - va_start(args, format); - - ret = BIO_vsnprintf(buf, n, format, args); - + int ret = BIO_vsnprintf(buf, n, format, args); va_end(args); return ret; }