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/common_kvm_arm64.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'executor/common_kvm_arm64.h') diff --git a/executor/common_kvm_arm64.h b/executor/common_kvm_arm64.h index beb794a79..36c95cba8 100644 --- a/executor/common_kvm_arm64.h +++ b/executor/common_kvm_arm64.h @@ -45,8 +45,7 @@ static long syz_kvm_setup_cpu(volatile long a0, volatile long a1, volatile long uint32 features = 0; if (opt_count > 1) opt_count = 1; - uintptr_t i; - for (i = 0; i < opt_count; i++) { + for (uintptr_t i = 0; i < opt_count; i++) { uint64 typ = opt_array_ptr[i].typ; uint64 val = opt_array_ptr[i].val; switch (typ) { @@ -56,7 +55,7 @@ static long syz_kvm_setup_cpu(volatile long a0, volatile long a1, volatile long } } - for (i = 0; i < guest_mem_size / page_size; i++) { + for (uintptr_t i = 0; i < guest_mem_size / page_size; i++) { struct kvm_userspace_memory_region memreg; memreg.slot = i; memreg.flags = 0; // can be KVM_MEM_LOG_DIRTY_PAGES | KVM_MEM_READONLY -- cgit mrf-deployment