diff options
author | David Benjamin <davidben@google.com> | 2016-07-12 02:38:56 +0300 |
---|---|---|
committer | Adam Langley <agl@google.com> | 2016-07-12 02:51:47 +0300 |
commit | 0ee319322c06a27efd5ade28263fb3cc7a16263e (patch) | |
tree | 18057ae9c99c1a60501df32b755c141ab9b0635a | |
parent | ee51a22905de566374280ebe60e345900f585d52 (diff) |
Breaking news: 1998 has come and gone.
Last month's canary for loop did not die in the coal mine of decrepit
toolchains. Make a note of this in STYLE.md so we know to start breeding
more of them. We can indeed declare index variables like it's 1999.
I haven't bothered to convert all of our for loops because that will be
tedious, but we can do it as we touch the code. Or if someone feels
really really bored.
BUG=47
Change-Id: Ib76c0767c1b509e825eac66f8c2e3ee2134e2493
Reviewed-on: https://boringssl-review.googlesource.com/8740
Reviewed-by: Adam Langley <agl@google.com>
-rw-r--r-- | STYLE.md | 4 | ||||
-rw-r--r-- | crypto/mem.c | 17 |
2 files changed, 7 insertions, 14 deletions
@@ -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; } |