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>
This commit is contained in:
David Benjamin 2016-07-11 19:38:56 -04:00 committed by Adam Langley
parent ee51a22905
commit 0ee319322c
2 changed files with 7 additions and 14 deletions

View File

@ -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 our target platforms. Typically, Chromium's target MSVC is the most
restrictive. 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. Comments should be `/* C-style */` for consistency.

View File

@ -83,8 +83,6 @@ OPENSSL_MSVC_PRAGMA(warning(pop))
void *OPENSSL_realloc_clean(void *ptr, size_t old_size, size_t new_size) { void *OPENSSL_realloc_clean(void *ptr, size_t old_size, size_t new_size) {
void *ret = NULL;
if (ptr == NULL) { if (ptr == NULL) {
return OPENSSL_malloc(new_size); 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; return NULL;
} }
ret = OPENSSL_malloc(new_size); void *ret = OPENSSL_malloc(new_size);
if (ret == NULL) { if (ret == NULL) {
return NULL; return NULL;
} }
@ -143,10 +141,9 @@ uint32_t OPENSSL_hash32(const void *ptr, size_t len) {
static const uint32_t kOffsetBasis = 2166136261u; static const uint32_t kOffsetBasis = 2166136261u;
const uint8_t *in = ptr; const uint8_t *in = ptr;
size_t i;
uint32_t h = kOffsetBasis; uint32_t h = kOffsetBasis;
for (i = 0; i < len; i++) { for (size_t i = 0; i < len; i++) {
h ^= in[i]; h ^= in[i];
h *= kPrime; 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 OPENSSL_strnlen(const char *s, size_t len) {
size_t i; for (size_t i = 0; i < len; i++) {
for (i = 0; i < len; i++) {
if (s[i] == 0) { if (s[i] == 0) {
return i; 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, ...) { int BIO_snprintf(char *buf, size_t n, const char *format, ...) {
va_list args; va_list args;
int ret;
va_start(args, format); va_start(args, format);
int ret = BIO_vsnprintf(buf, n, format, args);
ret = BIO_vsnprintf(buf, n, format, args);
va_end(args); va_end(args);
return ret; return ret;
} }