From ed0120009fcdc809c1e1e6c81385d7009b3e9006 Mon Sep 17 00:00:00 2001 From: Tj Date: Wed, 7 Oct 2015 22:55:46 +0100 Subject: [PATCH] Tidy up a few lint issues --- cfe_generate_password.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/cfe_generate_password.c b/cfe_generate_password.c index 049b15b..47a4ba8 100644 --- a/cfe_generate_password.c +++ b/cfe_generate_password.c @@ -57,17 +57,16 @@ #include #include -#include #include #include static const float VERSION = 1.0f; -static const unsigned int TIMESTAMP_SIZE = 6; -static const unsigned int SEED_SIZE = 12; -static const unsigned int PASSWORD_SIZE = 8; -static const unsigned int MESSAGE_SIZE = 128; +static const size_t TIMESTAMP_SIZE = 6; +static const size_t SEED_SIZE = 12; +static const size_t PASSWORD_SIZE = 8; +static const size_t MESSAGE_SIZE = 128; -void +static void pr_usage() { fprintf(stderr, "%s\n", @@ -82,7 +81,7 @@ pr_usage() ); } -void +static void pr_error_exit(unsigned int usage, const char *error, ...) { va_list args; @@ -91,13 +90,13 @@ pr_error_exit(unsigned int usage, const char *error, ...) if (!error) return; va_start(args, error); - vsnprintf(error_message, MESSAGE_SIZE, error, args); + (void) vsnprintf(error_message, MESSAGE_SIZE, error, args); va_end(args); fprintf(stderr, "Error: %s\n", error_message); if (usage) pr_usage(); - exit(1); + exit(EXIT_FAILURE); } static const unsigned int passwords[8] = { @@ -111,12 +110,12 @@ static const unsigned int passwords[8] = { 0xC621E14A }; -unsigned int +static unsigned int generate_seed(char *mac, char *timestamp, char *seed) { unsigned int result = 0; if (mac && strlen(mac) == 17) { - unsigned int i; + size_t i; char *mac_ptr = mac + 9; size_t ts_len = strlen(timestamp); for (i = 0; i <= SEED_SIZE; ++i) { @@ -136,18 +135,20 @@ generate_seed(char *mac, char *timestamp, char *seed) return result; } -unsigned int +static unsigned int generate_pass(char *seed, char *password) { unsigned int result = 0; if (seed && strlen(seed) == 12) { - unsigned int timestamp = 0; - unsigned byte = 0; - sscanf(seed, "%06x", ×tamp); - sscanf(&seed[10], "%02x", &byte); - unsigned int key = byte & 0x07; - unsigned int pass = (passwords[key] + timestamp) ^ timestamp; + unsigned int timestamp, byte, key, pass; + timestamp = byte = 0; + if(! sscanf(seed, "%06x", ×tamp)) + pr_error_exit(1, "unable to parse seed's timestamp"); + if (! sscanf(&seed[10], "%02x", &byte)) + pr_error_exit(1, "unable to parse seed's MAC address"); + key = byte & 0x07; + pass = (passwords[key] + timestamp) ^ timestamp; snprintf(password, PASSWORD_SIZE + 1, "%08x", pass); result = 1; } else @@ -167,7 +168,6 @@ main(int argc, char **argv, char **env) else { unsigned int arg; char *MAC_ADDR = NULL; - char *MODEL = NULL; char timestamp[TIMESTAMP_SIZE + 1]; char seed[SEED_SIZE + 1]; char password[PASSWORD_SIZE + 1]; @@ -177,7 +177,7 @@ main(int argc, char **argv, char **env) opt_seed = opt_pass = opt_ts = 0; strncpy(timestamp, "000000", TIMESTAMP_SIZE); - for (arg = 1; arg < argc; ++arg) { + for (arg = 1; arg < (unsigned) argc; ++arg) { size_t arg_len = strlen(argv[arg]); if (argv[arg][0] == '-') { -- 2.17.1