From 424dd8e7b52828cad44ce653a5d4ac30670f5e2c Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 13 Aug 2020 16:37:32 +0200 Subject: 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. --- executor/executor.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'executor/executor.cc') diff --git a/executor/executor.cc b/executor/executor.cc index 04d0259f6..ca24ffd07 100644 --- a/executor/executor.cc +++ b/executor/executor.cc @@ -809,8 +809,8 @@ retry: thread_t* schedule_call(int call_index, int call_num, bool colliding, uint64 copyout_index, uint64 num_args, uint64* args, uint64* pos) { // Find a spare thread to execute the call. - int i; - for (i = 0; i < kMaxThreads; i++) { + int i = 0; + for (; i < kMaxThreads; i++) { thread_t* th = &threads[i]; if (!th->created) thread_create(th, i); @@ -1504,8 +1504,8 @@ void debug_dump_data(const char* data, int length) { if (!flag_debug) return; - int i; - for (i = 0; i < length; i++) { + int i = 0; + for (; i < length; i++) { debug("%02x ", data[i] & 0xff); if (i % 16 == 15) debug("\n"); -- cgit mrf-deployment