From: Hugo Villeneuve Date: Thu, 13 Feb 2014 05:52:19 +0000 (-0500) Subject: Fix splint warnings X-Git-Tag: v2.0.1~8 X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=c91e69d435a938a1ee46b0881c50ee4816223bb0;hp=e417485aaf141647fcb32f45e38bbc5163abb2b4;p=emu8051.git Fix splint warnings --- diff --git a/src/cli/main.c b/src/cli/main.c index 35f78d0..0e41d1b 100644 --- a/src/cli/main.c +++ b/src/cli/main.c @@ -33,7 +33,7 @@ main(int argc, char **argv) if (options.filename != NULL) { rc = hexfile_load(options.filename); if (!rc) - exit(1); + exit(EXIT_FAILURE); } console_reset(); @@ -44,8 +44,8 @@ main(int argc, char **argv) } else { menu_display_usage(); console_show_registers(); - yyparse(); + (void) yyparse(); } - return 0; + exit(EXIT_SUCCESS); } diff --git a/src/cli/menu.c b/src/cli/menu.c index 8d4c007..524e4f3 100644 --- a/src/cli/menu.c +++ b/src/cli/menu.c @@ -58,6 +58,7 @@ menu_get_input(char *buf, ssize_t size) if ((int) strlen(line) > max_len) { printf("input line too long"); + free(line); return YY_NULL; } @@ -189,7 +190,7 @@ console_exec(int num) log_info("Program executing..."); - cpu8051_run(num, kbhit); + (void) cpu8051_run(num, kbhit); if (kbhit()) { (void) getch(); /* Flush key */ @@ -205,7 +206,7 @@ console_exec(int num) void console_trace(void) { - cpu8051_exec(); + (void) cpu8051_exec(); console_show_registers(); disassemble_num(cpu8051.pc, 1); } diff --git a/src/common/log.c b/src/common/log.c index 1a3d218..1cdc210 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -49,7 +49,7 @@ log_debug(const char *format, ...) log_prefix_package_name(stream, "debug"); va_start(ap, format); - vfprintf(stream, format, ap); + (void) vfprintf(stream, format, ap); va_end(ap); log_suffix_newline(stream); @@ -67,7 +67,7 @@ log_info(const char *format, ...) log_prefix_package_name(stream, "info"); va_start(ap, format); - vfprintf(stream, format, ap); + (void) vfprintf(stream, format, ap); va_end(ap); log_suffix_newline(stream); @@ -85,7 +85,7 @@ log_warn(const char *format, ...) log_prefix_package_name(stream, "warn"); va_start(ap, format); - vfprintf(stream, format, ap); + (void) vfprintf(stream, format, ap); va_end(ap); log_suffix_newline(stream); @@ -101,7 +101,7 @@ log_err(const char *format, ...) log_prefix_package_name(stream, "error"); va_start(ap, format); - vfprintf(stream, format, ap); + (void) vfprintf(stream, format, ap); va_end(ap); log_suffix_newline(stream); @@ -117,7 +117,7 @@ log_fail(const char *format, ...) log_prefix_package_name(stream, "error"); va_start(ap, format); - vfprintf(stream, format, ap); + (void) vfprintf(stream, format, ap); va_end(ap); log_suffix_newline(stream); diff --git a/src/common/memory.c b/src/common/memory.c index bb0742b..daaa1fa 100644 --- a/src/common/memory.c +++ b/src/common/memory.c @@ -50,14 +50,12 @@ mem_init(void) m = &mem_infos[k]; if (m->size > m->max_size) { - log_err("Memory size invalid (max = %d)", m->max_size); - exit(1); + log_fail("Memory size invalid (max = %d)", m->max_size); } m->buf = malloc(m->size); if (m->buf == NULL) { - log_err("%s", strerror(errno)); - exit(1); + log_fail("%s", strerror(errno)); } memset(m->buf, 0x00, m->size); @@ -319,13 +317,13 @@ mem_dump(unsigned int address, int size, enum mem_id_t id) return; for (offset = 0; offset < size; offset += 16) { - unsigned char data[16]; + uint8_t data[16]; printf("%.4X ", address + offset); for (col = 0; col < 16; col++) { data[col] = mem_read8(id, address + offset + col); - printf(" %.2X", (int) data[col]); + printf(" %.2X", data[col]); } printf(" "); @@ -333,7 +331,7 @@ mem_dump(unsigned int address, int size, enum mem_id_t id) for (col = 0; col < 16; col++) { if ((int) data[col] >= 32 && (int) data[col] <= 126) - printf("%c", data[col]); + printf("%c", (char) data[col]); else printf("."); } diff --git a/src/common/options.c b/src/common/options.c index 4b9b905..59c5d26 100644 --- a/src/common/options.c +++ b/src/common/options.c @@ -10,7 +10,6 @@ # include "config.h" #endif -#include #include #include #include @@ -59,7 +58,7 @@ decode_debug_option(char *arg, struct argp_state *state) char *endptr; int log_level; - log_level = strtol(arg, &endptr, 0); + log_level = (int) strtol(arg, &endptr, 0); if (*endptr != '\0') { log_err("Invalid log level"); @@ -87,13 +86,13 @@ decode_memory_size(char *arg, struct argp_state *state, int memid) else if (memid == EXT_MEM_ID) dest = &options.xram_size; else - exit(1); /* Programming error. */ + exit(EXIT_FAILURE); /* Programming error. */ /* * Sizes versus max memory sizes will be checked when calling * memory_init(). */ - *dest = strtol(arg, &endptr, 0); + *dest = (int) strtol(arg, &endptr, 0); if (*endptr != '\0') { log_err("Invalid memory size"); @@ -106,7 +105,7 @@ decode_address(char *arg, struct argp_state *state, uint16_t *dest) { char *endptr; - *dest = strtol(arg, &endptr, 0); + *dest = (uint16_t) strtol(arg, &endptr, 0); if (*endptr != '\0') { log_err("Invalid address"); @@ -163,6 +162,8 @@ static struct argp argp = {argp_options, parse_opt, args_doc, str_doc, void parse_command_line_options(int argc, char *argv[]) { + error_t rc; + /* Setting default values. */ options.filename = NULL; options.pram_size = PGM_MEM_DEFAULT_SIZE; @@ -172,5 +173,7 @@ parse_command_line_options(int argc, char *argv[]) options.stop_address = 0; /* 0 means stop address is disabled. */ /* Parse our arguments. */ - argp_parse(&argp, argc, argv, 0, 0, NULL); + rc = argp_parse(&argp, argc, argv, 0, 0, NULL); + if (rc != 0) + log_fail("Failure to parse command line arguments"); } diff --git a/src/common/psw.c b/src/common/psw.c index 36ab5e2..1d24597 100644 --- a/src/common/psw.c +++ b/src/common/psw.c @@ -12,13 +12,13 @@ /* Returns 0 or 1 */ int -psw_read_bit(int bit) +psw_read_bit(unsigned int bit) { return (mem_read8(INT_MEM_ID, _PSW_) >> bit) & 0x01; } void -psw_write_bit(int bit, int val) +psw_write_bit(unsigned int bit, int val) { uint8_t psw = mem_read8(INT_MEM_ID, _PSW_); diff --git a/src/common/psw.h b/src/common/psw.h index 54b3371..9fadb02 100644 --- a/src/common/psw.h +++ b/src/common/psw.h @@ -10,10 +10,10 @@ #define PSW_H 1 int -psw_read_bit(int bit); +psw_read_bit(unsigned int bit); void -psw_write_bit(int bit, int val); +psw_write_bit(unsigned int bit, int val); int psw_read_cy(void);