From 2955ff1b0e11d09a5414686c3216e611d610e61f Mon Sep 17 00:00:00 2001 From: Kevin Tew Date: Thu, 22 Oct 2009 17:17:32 +0000 Subject: [PATCH] Silence gcc 4.4.1 compiler warnings svn: r16411 --- src/mzscheme/dynsrc/ustart.c | 13 +++++-- src/mzscheme/src/gmp/gmp.c | 3 +- src/mzscheme/src/numstr.c | 56 ++++++++++++++++++--------- src/mzscheme/src/port.c | 5 ++- src/mzscheme/src/stxobj.c | 5 +++ src/mzscheme/src/unwind/libunwind_i.h | 4 +- 6 files changed, 61 insertions(+), 25 deletions(-) diff --git a/src/mzscheme/dynsrc/ustart.c b/src/mzscheme/dynsrc/ustart.c index b8cb44cede..64e81f40b1 100644 --- a/src/mzscheme/dynsrc/ustart.c +++ b/src/mzscheme/dynsrc/ustart.c @@ -10,6 +10,7 @@ #include #include #include +#include /* The config string after : is replaced with ! followed by a sequence of little-endian 4-byte ints: @@ -95,9 +96,9 @@ static int is_x_flag(char *s) return 0; } -static void write_str(int fd, char *s) +static int write_str(int fd, char *s) { - write(fd, s, strlen(s)); + return write(fd, s, strlen(s)); } #if 0 @@ -330,7 +331,13 @@ int main(int argc, char **argv) fd = open(me, O_RDONLY, 0); lseek(fd, prog_end, SEEK_SET); - read(fd, data, end - prog_end); + { + int expected_length = end - prog_end; + if (expected_length != read(fd, data, expected_length)) { + printf("read failed to read all %i bytes from file %s\n", expected_length, me); + abort(); + } + } close(fd); exe_path = data; diff --git a/src/mzscheme/src/gmp/gmp.c b/src/mzscheme/src/gmp/gmp.c index 6cd66010ba..96148b7baf 100644 --- a/src/mzscheme/src/gmp/gmp.c +++ b/src/mzscheme/src/gmp/gmp.c @@ -5836,7 +5836,8 @@ void scheme_gmp_tls_snapshot(long *s, long *save) void scheme_gmp_tls_restore_snapshot(long *s, void *data, long *save, int do_free) { - long other[6]; + /* silence gcc "may be used uninitialized in this function" warnings */ + long other[6] = {0,0,0,0,0,0}; void *other_data; if (do_free == 2) { diff --git a/src/mzscheme/src/numstr.c b/src/mzscheme/src/numstr.c index 2f71c47a87..581df7671b 100644 --- a/src/mzscheme/src/numstr.c +++ b/src/mzscheme/src/numstr.c @@ -1676,23 +1676,41 @@ static Scheme_Object *bytes_to_integer (int argc, Scheme_Object *argv[]) switch(slen) { case 2: - if (sgned) - return scheme_make_integer(((short *)str)[0]); - else - return scheme_make_integer(((unsigned short *)str)[0]); + if (sgned) { + short val; + memcpy(&val, str, sizeof(short)); + return scheme_make_integer(val); + } + else { + unsigned short val; + memcpy(&val, str, sizeof(unsigned short)); + return scheme_make_integer(val); + } break; case 4: - if (sgned) - return scheme_make_integer_value(((int *)str)[0]); - else - return scheme_make_integer_value_from_unsigned(((unsigned int *)str)[0]); + if (sgned) { + int val; + memcpy(&val, str, sizeof(int)); + return scheme_make_integer_value(val); + } + else { + unsigned int val; + memcpy(&val, str, sizeof(unsigned int)); + return scheme_make_integer_value_from_unsigned(val); + } break; default: #ifdef SIXTY_FOUR_BIT_INTEGERS - if (sgned) - return scheme_make_integer_value(((long *)str)[0]); - else - return scheme_make_integer_value_from_unsigned(((unsigned long *)str)[0]); + if (sgned) { + long val; + memcpy(&val, str, sizeof(long)); + return scheme_make_integer_value(val); + } + else { + unsigned long val; + memcpy(&val, str, sizeof(unsigned long)); + return scheme_make_integer_value_from_unsigned(val); + } break; #else # ifndef NO_LONG_LONG_TYPE @@ -1875,19 +1893,21 @@ static Scheme_Object *integer_to_bytes(int argc, Scheme_Object *argv[]) case 2: { if (sgned) { - *(unsigned short *)str = (unsigned short)(val); + unsigned short value = val; + memcpy(str, &value, sizeof(unsigned short)); } else { - *(short *)str = (short)(val); + short value = val; + memcpy(str, &value, sizeof(short)); } } break; case 4: if (sgned) { - unsigned int sv = val; - *(unsigned int *)str = sv; + unsigned int value = val; + memcpy(str, &value, sizeof(unsigned int)); } else { - int sv = val; - *(int *)str = sv; + int value = val; + memcpy(str, &value, sizeof(int)); } break; default: diff --git a/src/mzscheme/src/port.c b/src/mzscheme/src/port.c index 507c87f973..5272e32c7b 100644 --- a/src/mzscheme/src/port.c +++ b/src/mzscheme/src/port.c @@ -8350,8 +8350,11 @@ static void default_sleep(float v, void *fds) #if defined(FILES_HAVE_FDS) /* Clear external event flag */ if (external_event_fd) { + int rc; char buf[10]; - read(external_event_fd, buf, 10); + do { + rc = read(external_event_fd, buf, 10); + } while ((rc == -1) && errno == EINTR); } #endif } diff --git a/src/mzscheme/src/stxobj.c b/src/mzscheme/src/stxobj.c index 8bec65a15b..3cd2cc0512 100644 --- a/src/mzscheme/src/stxobj.c +++ b/src/mzscheme/src/stxobj.c @@ -362,6 +362,11 @@ XFORM_NONGCING static void WRAP_POS_SET_FIRST(Wrap_Pos *w) w->a = a; } } + /* silence gcc "may be used uninitialized in this function" warnings */ + else { + w->a = NULL; + w->is_limb = 0; + } } XFORM_NONGCING static MZ_INLINE void DO_WRAP_POS_INC(Wrap_Pos *w) diff --git a/src/mzscheme/src/unwind/libunwind_i.h b/src/mzscheme/src/unwind/libunwind_i.h index ee1cff6340..e9c7926fa7 100644 --- a/src/mzscheme/src/unwind/libunwind_i.h +++ b/src/mzscheme/src/unwind/libunwind_i.h @@ -215,10 +215,10 @@ do { \ # define dprintf(format...) #endif -static ALWAYS_INLINE void +static ALWAYS_INLINE int print_error (const char *string) { - write (2, string, strlen (string)); + return write (2, string, strlen (string)); } #define mi_init UNWI_ARCH_OBJ(mi_init)