diff --git a/src/systemcmds/reflect/reflect.c b/src/systemcmds/reflect/reflect.c index fe5f0f0359..683ff7c6ea 100644 --- a/src/systemcmds/reflect/reflect.c +++ b/src/systemcmds/reflect/reflect.c @@ -54,7 +54,7 @@ __EXPORT int reflect_main(int argc, char *argv[]); #define MAX_BLOCKS 1000 static uint32_t nblocks; struct block { - uint32_t v[256]; + uint32_t v[256]; }; static struct block *blocks[MAX_BLOCKS]; @@ -62,50 +62,59 @@ static struct block *blocks[MAX_BLOCKS]; static void allocate_blocks(void) { - while (nblocks < MAX_BLOCKS) { - blocks[nblocks] = calloc(1, sizeof(struct block)); - if (blocks[nblocks] == NULL) { - break; - } - for (uint32_t i=0; iv)/sizeof(uint32_t); i++) { - blocks[nblocks]->v[i] = VALUE(i); - } - nblocks++; - } - printf("Allocated %u blocks\n", nblocks); + while (nblocks < MAX_BLOCKS) { + blocks[nblocks] = calloc(1, sizeof(struct block)); + + if (blocks[nblocks] == NULL) { + break; + } + + for (uint32_t i = 0; i < sizeof(blocks[nblocks]->v) / sizeof(uint32_t); i++) { + blocks[nblocks]->v[i] = VALUE(i); + } + + nblocks++; + } + + printf("Allocated %u blocks\n", nblocks); } static void check_blocks(void) { - for (uint32_t n=0; nv)/sizeof(uint32_t); i++) { - assert(blocks[n]->v[i] == VALUE(i)); - } - } + for (uint32_t n = 0; n < nblocks; n++) { + for (uint32_t i = 0; i < sizeof(blocks[nblocks]->v) / sizeof(uint32_t); i++) { + assert(blocks[n]->v[i] == VALUE(i)); + } + } } int reflect_main(int argc, char *argv[]) { - uint32_t total = 0; - printf("Starting reflector\n"); + uint32_t total = 0; + printf("Starting reflector\n"); - allocate_blocks(); + allocate_blocks(); - while (true) { - char buf[128]; - ssize_t n = read(0, buf, sizeof(buf)); - if (n < 0) { - break; - } - if (n > 0) { - write(1, buf, n); - } - total += n; - if (total > 1024000) { - check_blocks(); - total = 0; - } - } - return OK; + while (true) { + char buf[128]; + ssize_t n = read(0, buf, sizeof(buf)); + + if (n < 0) { + break; + } + + if (n > 0) { + write(1, buf, n); + } + + total += n; + + if (total > 1024000) { + check_blocks(); + total = 0; + } + } + + return OK; }