From: Gwendal Grignou Date: Thu, 13 Oct 2016 21:25:33 +0000 (-0700) Subject: Fix compilation errors: X-Git-Tag: v1.0~17^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=19b336bc559dcbda83491d80e12d68c826a87529;p=users%2Fhch%2Fnvme-cli.git Fix compilation errors: While compiling nvme-cli for ChromeOS, the compiler founds minor issues in the code: - unsigned and sizet_t can never be negative. - use fabs instead of llabs when argument is a double. Signed-off-by: Gwendal Grignou --- diff --git a/argconfig.c b/argconfig.c index 94d9487..47c9dc8 100644 --- a/argconfig.c +++ b/argconfig.c @@ -244,28 +244,28 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc, } *((int *)value_addr) = tmp; } else if (s->config_type == CFG_BYTE) { - uint8_t tmp = strtoul(optarg, &endptr, 0); - if (errno || tmp < 0 || optarg == endptr) { + unsigned long tmp = strtoul(optarg, &endptr, 0); + if (errno || tmp >= (1 << 8) || optarg == endptr) { fprintf(stderr, - "Expected positive argument for '%s' but got '%s'!\n", + "Expected byte argument for '%s' but got '%s'!\n", long_opts[option_index].name, optarg); goto exit; } *((uint8_t *) value_addr) = tmp; } else if (s->config_type == CFG_SHORT) { - uint16_t tmp = strtoul(optarg, &endptr, 0); - if (errno || tmp < 0 || optarg == endptr) { + unsigned long tmp = strtoul(optarg, &endptr, 0); + if (errno || tmp >= (1 << 16) || optarg == endptr) { fprintf(stderr, - "Expected positive argument for '%s' but got '%s'!\n", + "Expected short argument for '%s' but got '%s'!\n", long_opts[option_index].name, optarg); goto exit; } *((uint16_t *) value_addr) = tmp; } else if (s->config_type == CFG_POSITIVE) { uint32_t tmp = strtoul(optarg, &endptr, 0); - if (errno || tmp < 0 || optarg == endptr) { + if (errno || optarg == endptr) { fprintf(stderr, - "Expected positive argument for '%s' but got '%s'!\n", + "Expected word argument for '%s' but got '%s'!\n", long_opts[option_index].name, optarg); goto exit; } @@ -273,7 +273,7 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc, } else if (s->config_type == CFG_INCREMENT) { (*((int *)value_addr))++; } else if (s->config_type == CFG_LONG) { - *((long *)value_addr) = strtoul(optarg, &endptr, 0); + *((unsigned long *)value_addr) = strtoul(optarg, &endptr, 0); if (errno || optarg == endptr) { fprintf(stderr, "Expected long integer argument for '%s' but got '%s'!\n", diff --git a/fabrics.c b/fabrics.c index 0718446..51e424e 100644 --- a/fabrics.c +++ b/fabrics.c @@ -166,8 +166,7 @@ static int add_ctrl(const char *argstr) { substring_t args[MAX_OPT_ARGS]; char buf[BUF_SIZE], *options, *p; - size_t len = strlen(argstr); - int token, ret, fd; + int token, ret, fd, len = strlen(argstr); fd = open(PATH_NVME_FABRICS, O_RDWR); if (fd < 0) { diff --git a/suffix.c b/suffix.c index 6f2a956..086cb88 100644 --- a/suffix.c +++ b/suffix.c @@ -34,6 +34,7 @@ #include #include #include +#include static struct si_suffix { double magnitude; @@ -99,7 +100,7 @@ const char *suffix_dbinary_get(double *value) struct binary_suffix *s; for (s = binary_suffixes; s->shift != 0; s++) { - if (llabs(*value) >= (1LL << s->shift)) { + if (fabs(*value) >= (1LL << s->shift)) { *value = *value / (1 << s->shift); return s->suffix; }