diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-08-13 16:37:32 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-08-14 09:40:08 +0200 |
| commit | 424dd8e7b52828cad44ce653a5d4ac30670f5e2c (patch) | |
| tree | 55f116b53a92ee8de3f1d5aafbba9566f777e869 /executor/test.h | |
| parent | 54ce1ed6b9fcb3b8d77c43dd4b3533e70cade414 (diff) | |
executor: warn about C89-style var declarations
We generally use the newer C99 var declarations combined with initialization because:
- declarations are more local, reduced scope
- fewer lines of code
- less potential for using uninit vars and other bugs
However, we have some relic code from times when we did not understand
if we need to stick with C89 or not. Also some external contributions
that don't follow style around.
Add a static check for C89-style declarations and fix existing precedents.
Akaros toolchain uses -std=gnu89 (or something) and does not allow
variable declarations inside of for init statement. And we can't switch
it to -std=c99 because Akaros headers are C89 themselves.
So in common.h we need to declare loop counters outside of for.
Diffstat (limited to 'executor/test.h')
| -rw-r--r-- | executor/test.h | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/executor/test.h b/executor/test.h index cec0228e2..bd30fb372 100644 --- a/executor/test.h +++ b/executor/test.h @@ -176,19 +176,17 @@ static int test_csum_inet_acc() { uint8 buffer[128]; - int test; - for (test = 0; test < 256; test++) { + for (int test = 0; test < 256; test++) { int size = rand_int_range(1, 128); int step = rand_int_range(1, 8) * 2; - int i; - for (i = 0; i < size; i++) + for (int i = 0; i < size; i++) buffer[i] = rand_int_range(0, 255); struct csum_inet csum_acc; csum_inet_init(&csum_acc); - for (i = 0; i < size / step; i++) + for (int i = 0; i < size / step; i++) csum_inet_update(&csum_acc, &buffer[i * step], step); if (size % step != 0) csum_inet_update(&csum_acc, &buffer[size - size % step], size % step); |
