Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 59958992 in mainline


Ignore:
Timestamp:
2017-12-22T15:08:49Z (4 years ago)
Author:
Petr Mánek <petr.manek@…>
Branches:
lfn, master
Children:
8e16454
Parents:
acb9aa7
Message:

tmon: use ARRAY_SIZE to enumerate static arrays

Location:
uspace/app/tmon
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/tmon/burst_tests.c

    racb9aa7 r59958992  
    4040#include <getopt.h>
    4141#include <usbdiag_iface.h>
     42#include <macros.h>
    4243#include "commands.h"
    4344#include "tf.h"
     
    115116        { .prefix = 'G', .factor = 1ul << 30 },
    116117        { .prefix = 'M', .factor = 1ul << 20 },
    117         { .prefix = 'k', .factor = 1ul << 10 },
    118         { /* NULL-terminated */ }
     118        { .prefix = 'k', .factor = 1ul << 10 }
    119119};
    120120
    121121static char * format_size(double size, const char *fmt)
    122122{
    123         int i;
    124         for (i = 0; units[i].prefix; ++i) {
     123        unsigned i;
     124        for (i = 0; i < ARRAY_SIZE(units); ++i) {
    125125                if (units[i].factor <= size)
    126126                        break;
    127127        }
    128128
    129         char prefix[2] = { '\0', '\0' };
     129        char prefix[] = { '\0', '\0' };
    130130        double factor = 1;
    131131
    132         if (units[i].prefix) {
     132        if (i < ARRAY_SIZE(units)) {
    133133                prefix[0] = units[i].prefix;
    134134                factor = units[i].factor;
  • uspace/app/tmon/main.c

    racb9aa7 r59958992  
    3636
    3737#include <stdio.h>
     38#include <macros.h>
    3839#include "commands.h"
    3940
     
    8283                .description = "Write to isochronous endpoint as fast as possible.",
    8384                .action = tmon_burst_isoch_out,
    84         },
    85         { /* NULL-terminated */ }
     85        }
    8686};
    8787
     
    102102                .short_name = 's',
    103103                .description = "Set the data size transferred in a single cycle."
    104         },
    105         { /* NULL-terminated */ }
     104        }
    106105};
    107106
     
    111110        printf("Usage: %s command [device] [options]\n\n", app_name);
    112111
    113         for (int i = 0; commands[i].name; ++i) {
     112        for (unsigned i = 0; i < ARRAY_SIZE(commands); ++i) {
    114113                printf(INDENT "%s - %s\n", commands[i].name, commands[i].description);
    115114        }
    116115
    117116        puts("\n");
    118         for (int i = 0; options[i].long_name; ++i) {
     117        for (unsigned i = 0; i < ARRAY_SIZE(options); ++i) {
    119118                printf(INDENT "-%c --%s\n" INDENT INDENT "%s\n", options[i].short_name, options[i].long_name, options[i].description);
    120119        }
     
    127126        // Find a command to execute.
    128127        tmon_cmd_t *cmd = NULL;
    129         for (int i = 0; argc > 1 && commands[i].name; ++i) {
     128        for (unsigned i = 0; argc > 1 && i < ARRAY_SIZE(commands); ++i) {
    130129                if (str_cmp(argv[1], commands[i].name) == 0) {
    131130                        cmd = commands + i;
Note: See TracChangeset for help on using the changeset viewer.