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().
This commit is contained in:
Mike Frysinger 2021-05-07 00:31:05 -04:00
parent 0ae995e2df
commit 44056b7ce4
5 changed files with 41 additions and 21 deletions

View file

@ -1,3 +1,15 @@
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.

28
sim/m32c/configure vendored
View file

@ -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"

View file

@ -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

View file

@ -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 ();
}

View file

@ -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;