aboutsummaryrefslogtreecommitdiff
path: root/sim/m32c
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2021-05-07 00:31:05 -0400
committerMike Frysinger <vapier@gentoo.org>2021-05-07 00:36:26 -0400
commit44056b7ce43618094e61bf856d77c798628cac83 (patch)
tree9aa2e47efceff17e1f9381e1f608786aa65af106 /sim/m32c
parent0ae995e2df001ab7c45c4bc596c4b0b734910c08 (diff)
downloadfsf-binutils-gdb-44056b7ce43618094e61bf856d77c798628cac83.zip
fsf-binutils-gdb-44056b7ce43618094e61bf856d77c798628cac83.tar.gz
fsf-binutils-gdb-44056b7ce43618094e61bf856d77c798628cac83.tar.bz2
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().
Diffstat (limited to 'sim/m32c')
-rw-r--r--sim/m32c/ChangeLog12
-rwxr-xr-xsim/m32c/configure28
-rw-r--r--sim/m32c/configure.ac2
-rw-r--r--sim/m32c/mem.c15
-rw-r--r--sim/m32c/trace.c5
5 files changed, 41 insertions, 21 deletions
diff --git a/sim/m32c/ChangeLog b/sim/m32c/ChangeLog
index aedcb6a..f8842f5 100644
--- a/sim/m32c/ChangeLog
+++ b/sim/m32c/ChangeLog
@@ -1,5 +1,17 @@
2021-05-07 Mike Frysinger <vapier@gentoo.org>
+ * 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 <vapier@gentoo.org>
+
* m32c.opc: Add scope braces around a few segments.
* r8c.opc: Likewise.
diff --git a/sim/m32c/configure b/sim/m32c/configure
index 4d5f524..7c283c2 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 a69fa12..de1587e 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 1351355..4baf71f 100644
--- a/sim/m32c/mem.c
+++ b/sim/m32c/mem.c
@@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "config.h"
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -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 43a4604b..f871c01 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;