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().
+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.
+
+
+
+
+
+
+
+
+
+
+
+
# Check whether --enable-werror was given.
if test "${enable_werror+set}" = set; then :
enableval=$enable_werror; case "${enableval}" in
fi
WERROR_CFLAGS=""
+ if test "${ERROR_ON_WARNING}" = yes ; then
+ WERROR_CFLAGS="-Werror"
+ fi
build_warnings="-Wall -Wdeclaration-after-statement -Wpointer-arith \
-Wpointer-sign \
fi
-
-
-
-
-
-
-
-
-
-
-
-
-
hardware="cfi core pal glue "
sim_hw_cflags="-DWITH_HW=1"
sim_hw="$hardware"
SIM_AC_COMMON
-SIM_AC_OPTION_WARNINGS(no)
-
AC_CHECK_HEADERS_ONCE(m4_flatten([
termios.h
netinet/in.h
#include "config.h"
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
}
else
{
- write (m32c_console_ofd, &value, 1);
+ if (write (m32c_console_ofd, &value, 1) != 1)
+ printf ("write console failed: %s\n", strerror (errno));
}
}
break;
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 ();
}
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");
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 ();
}
struct stat s;
const char *found_filename, *slash;
FILE *file;
+ size_t ret;
found_filename = filename;
while (1)
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;