From: Mike Frysinger Date: Fri, 7 May 2021 04:31:05 +0000 (-0400) Subject: sim: m32c: clean up various warnings X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=44056b7ce43618094e61bf856d77c798628cac83;p=binutils-gdb.git sim: m32c: clean up various warnings A random grab bag of minor fixes to enable -Werror for this port. Check the return values of read & write calls and issue warnings when they fail. Fixup funky pointer math as the compiler doesn't like ++ on void*. Handle short reads with fread(). --- diff --git a/sim/m32c/ChangeLog b/sim/m32c/ChangeLog index aedcb6a22a8..f8842f57af1 100644 --- a/sim/m32c/ChangeLog +++ b/sim/m32c/ChangeLog @@ -1,3 +1,15 @@ +2021-05-07 Mike Frysinger + + * mem.c: Include errno.h. + (mem_put_byte): Print a warning when the write call fails. + (mem_put_blk): Declare local buf pointer and use it. + (mem_get_byte): Return 0 when the read call fails. + (mem_get_blk): Declare local buf pointer and use it. + * trace.c (load_file_and_line): Declare ret. + Assign fread to ret and use to index f->data. + * configure.ac: Delete SIM_AC_OPTION_WARNINGS call. + * configure: Regenerate. + 2021-05-07 Mike Frysinger * m32c.opc: Add scope braces around a few segments. diff --git a/sim/m32c/configure b/sim/m32c/configure index 4d5f524a766..7c283c21ca6 100755 --- a/sim/m32c/configure +++ b/sim/m32c/configure @@ -11850,6 +11850,18 @@ _ACEOF + + + + + + + + + + + + # Check whether --enable-werror was given. if test "${enable_werror+set}" = set; then : enableval=$enable_werror; case "${enableval}" in @@ -11866,6 +11878,9 @@ if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then fi WERROR_CFLAGS="" + if test "${ERROR_ON_WARNING}" = yes ; then + WERROR_CFLAGS="-Werror" + fi build_warnings="-Wall -Wdeclaration-after-statement -Wpointer-arith \ -Wpointer-sign \ @@ -11947,19 +11962,6 @@ $as_echo "${WARN_CFLAGS} ${WERROR_CFLAGS}" >&6; } fi - - - - - - - - - - - - - hardware="cfi core pal glue " sim_hw_cflags="-DWITH_HW=1" sim_hw="$hardware" diff --git a/sim/m32c/configure.ac b/sim/m32c/configure.ac index a69fa128293..de1587eaac1 100644 --- a/sim/m32c/configure.ac +++ b/sim/m32c/configure.ac @@ -23,8 +23,6 @@ AC_CONFIG_MACRO_DIRS([../m4 ../.. ../../config]) SIM_AC_COMMON -SIM_AC_OPTION_WARNINGS(no) - AC_CHECK_HEADERS_ONCE(m4_flatten([ termios.h netinet/in.h diff --git a/sim/m32c/mem.c b/sim/m32c/mem.c index 13513552cd0..4baf71fa672 100644 --- a/sim/m32c/mem.c +++ b/sim/m32c/mem.c @@ -20,6 +20,7 @@ along with this program. If not, see . */ #include "config.h" +#include #include #include #include @@ -294,7 +295,8 @@ mem_put_byte (int address, unsigned char value) } else { - write (m32c_console_ofd, &value, 1); + if (write (m32c_console_ofd, &value, 1) != 1) + printf ("write console failed: %s\n", strerror (errno)); } } break; @@ -367,11 +369,13 @@ mem_put_si (int address, unsigned long value) void mem_put_blk (int address, const void *bufptr, int nbytes) { + const unsigned char *buf = bufptr; + S ("<="); if (enable_counting) mem_counters[1][1] += nbytes; while (nbytes--) - mem_put_byte (address++, *(const unsigned char *) bufptr++); + mem_put_byte (address++, *buf++); E (); } @@ -443,7 +447,8 @@ mem_get_byte (int address) case 0x2ee: /* m32c uart1 rx */ { char c; - read (m32c_console_ifd, &c, 1); + if (read (m32c_console_ifd, &c, 1) != 1) + return 0; if (m32c_console_ifd == 0 && c == 3) /* Ctrl-C */ { printf ("Ctrl-C!\n"); @@ -535,11 +540,13 @@ mem_get_si (int address) void mem_get_blk (int address, void *bufptr, int nbytes) { + char *buf = bufptr; + S ("=>"); if (enable_counting) mem_counters[0][1] += nbytes; while (nbytes--) - *(char *) bufptr++ = mem_get_byte (address++); + *buf++ = mem_get_byte (address++); E (); } diff --git a/sim/m32c/trace.c b/sim/m32c/trace.c index 43a4604b946..f871c01d82b 100644 --- a/sim/m32c/trace.c +++ b/sim/m32c/trace.c @@ -130,6 +130,7 @@ load_file_and_line (const char *filename, int lineno) struct stat s; const char *found_filename, *slash; FILE *file; + size_t ret; found_filename = filename; while (1) @@ -148,8 +149,8 @@ load_file_and_line (const char *filename, int lineno) f->filename = strdup (filename); f->data = (char *) malloc (s.st_size + 2); file = fopen (found_filename, "rb"); - fread (f->data, 1, s.st_size, file); - f->data[s.st_size] = 0; + ret = fread (f->data, 1, s.st_size, file); + f->data[ret] = 0; fclose (file); f->nlines = 1;