From: Ivan Maidanski Date: Thu, 8 Sep 2011 10:17:26 +0000 (+0400) Subject: Resolve "comparison of signed and unsigned values" compiler warnings. X-Git-Tag: gc7_3alpha2~375 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=96f78917fe574353bc061c07d46d47ad9a105981;p=gc Resolve "comparison of signed and unsigned values" compiler warnings. * cord/cordprnt.c (CORD_vsprintf): Cast "prec" and "width" local variables to size_t. * dyn_load.c (GC_register_dynamic_libraries_dl_iterate_phdr): Change type of "i" local variable to int. * pthread_support.c (start_mark_threads): Likewise. * os_dep.c (GC_repeat_read): Change type of "num_read" to size_t. * os_dep.c (GC_get_maps): Change type of "result" local variable from int to ssize_t; cast "result" to size_t in comparison. * pthread_support.c (GC_remove_all_threads_but_me): Cast "result" to int. * pthread_support.c (GC_wait_for_gc_completion): Change type of "old_gc_no" local variable to word. * pthread_support.c (GC_lock): Change type of "i" local variable to unsigned. * tests/staticrootstest.c (main): Cast sizeof() value to int in comparisons. --- diff --git a/TODO b/TODO index 3d2a80dc..c46ff70d 100644 --- a/TODO +++ b/TODO @@ -25,9 +25,6 @@ Merge symbian branch to master. Merge useful code (if any) from iphone_libgc_6x branch. (Same for gcc_boehmgc and mono_libgc.) -Makefile.am: CFLAGS: Add -Wall -Wextra -Wno-unused-parameters. Resolve -compiler warnings (if any). - configure.host: Move contents to configure.ac and remove the file. windows-untested: Remove if CMake can generate MS Visual Studio 6.0, 7.0, 8.0 @@ -58,4 +55,3 @@ Cygwin: crashes with USE_MUNMAP: mmap(PROT_NONE) failed. Cygwin: autoreconf fails: possibly undefined macro: AC_MSG_ERROR, AS_IF at configure.ac:59 and configure.ac:694, respectively (autoreconf-2.68). - diff --git a/cord/cordprnt.c b/cord/cordprnt.c index fe4aea1a..f4c63868 100644 --- a/cord/cordprnt.c +++ b/cord/cordprnt.c @@ -210,12 +210,12 @@ int CORD_vsprintf(CORD * out, CORD format, va_list args) if (prec == VARIABLE) prec = va_arg(args, int); arg = va_arg(args, CORD); len = CORD_len(arg); - if (prec != NONE && len > prec) { + if (prec != NONE && len > (size_t)prec) { if (prec < 0) return(-1); arg = CORD_substr(arg, 0, prec); len = prec; } - if (width != NONE && len < width) { + if (width != NONE && len < (size_t)width) { char * blanks = GC_MALLOC_ATOMIC(width-len+1); memset(blanks, ' ', width-len); diff --git a/dyn_load.c b/dyn_load.c index c2d23bfb..e823c8d8 100644 --- a/dyn_load.c +++ b/dyn_load.c @@ -544,7 +544,7 @@ STATIC GC_bool GC_register_dynamic_libraries_dl_iterate_phdr(void) dl_iterate_phdr(GC_register_dynlib_callback, &did_something); if (did_something) { # ifdef PT_GNU_RELRO - size_t i; + int i; for (i = 0; i < n_load_segs; ++i) { if (load_segs[i].end > load_segs[i].start) { diff --git a/os_dep.c b/os_dep.c index 0290e2e0..1c0b73e1 100644 --- a/os_dep.c +++ b/os_dep.c @@ -149,7 +149,7 @@ /* we encounter EOF. */ STATIC ssize_t GC_repeat_read(int fd, char *buf, size_t count) { - ssize_t num_read = 0; + size_t num_read = 0; ssize_t result; ASSERT_CANCEL_DISABLED(); @@ -199,7 +199,7 @@ STATIC ssize_t GC_repeat_read(int fd, char *buf, size_t count) GC_INNER char * GC_get_maps(void) { int f; - int result; + ssize_t result; static char init_buf[1]; static char *maps_buf = init_buf; static size_t maps_buf_sz = 1; @@ -260,7 +260,7 @@ GC_INNER char * GC_get_maps(void) if (result <= 0) break; maps_size += result; - } while (result == maps_buf_sz-1); + } while ((size_t)result == maps_buf_sz-1); close(f); if (result <= 0) return 0; diff --git a/pthread_support.c b/pthread_support.c index f7a5ca42..377cbbf5 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -400,7 +400,7 @@ STATIC pthread_t GC_mark_threads[MAX_MARKERS]; static void start_mark_threads(void) { - unsigned i; + int i; pthread_attr_t attr; GC_ASSERT(I_DONT_HOLD_LOCK()); @@ -737,7 +737,7 @@ STATIC void GC_remove_all_threads_but_me(void) if (stat_buf[i] == '\n' && stat_buf[i+1] == 'c' && stat_buf[i+2] == 'p' && stat_buf[i+3] == 'u') { int cpu_no = atoi(&stat_buf[i + 4]); - if (cpu_no >= result) + if (cpu_no >= (int)result) result = cpu_no + 1; } } @@ -756,7 +756,7 @@ STATIC void GC_wait_for_gc_completion(GC_bool wait_for_all) GC_ASSERT(I_HOLD_LOCK()); ASSERT_CANCEL_DISABLED(); if (GC_incremental && GC_collection_in_progress()) { - int old_gc_no = GC_gc_no; + word old_gc_no = GC_gc_no; /* Make sure that no part of our stack is still on the mark stack, */ /* since it's about to be unmapped. */ @@ -1703,7 +1703,7 @@ GC_INNER void GC_lock(void) unsigned my_spin_max; static unsigned last_spins = 0; unsigned my_last_spins; - int i; + unsigned i; if (AO_test_and_set_acquire(&GC_allocate_lock) == AO_TS_CLEAR) { return; diff --git a/tests/staticrootstest.c b/tests/staticrootstest.c index 1f63fa24..222f2095 100644 --- a/tests/staticrootstest.c +++ b/tests/staticrootstest.c @@ -41,7 +41,7 @@ int main(void) root[i] = libsrl_mktree(12); GC_gcollect(); } - for (i = 0; i < sizeof(struct treenode); ++i) { + for (i = 0; i < (int)sizeof(struct treenode); ++i) { if (staticroot[i] != 0x42) return -1; } @@ -49,7 +49,7 @@ int main(void) root[i] = libsrl_mktree(12); GC_gcollect(); } - for (i = 0; i < sizeof(struct treenode); ++i) { + for (i = 0; i < (int)sizeof(struct treenode); ++i) { if (staticroot[i] != 0x42) return -1; }