gcc-3.3 as supplied with SuSE 8.2 ("gcc version 3.3 20030226
(prerelease) (SuSE Linux)") seems to complain about signed-vs-unsigned
comparisons, when -Wall is on.  This commit fixes (most of) those
complaints.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1638 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/demangle/cplus-dem.c b/coregrind/demangle/cplus-dem.c
index 4f708e6..ed16d24 100644
--- a/coregrind/demangle/cplus-dem.c
+++ b/coregrind/demangle/cplus-dem.c
@@ -1776,7 +1776,7 @@
 
 	  len = strlen (*mangled);
 
-	  for (i = 0; i < ARRAY_SIZE (optable); ++i)
+	  for (i = 0; i < (size_t)ARRAY_SIZE (optable); ++i)
 	    {
 	      size_t l = strlen (optable[i].in);
 
@@ -4683,7 +4683,7 @@
       if (declp->p - declp->b >= 10 /* op$assign_ */
 	  && memcmp (declp->b + 3, "assign_", 7) == 0)
 	{
-	  for (i = 0; i < ARRAY_SIZE (optable); i++)
+	  for (i = 0; i < (size_t)ARRAY_SIZE (optable); i++)
 	    {
 	      int len = declp->p - declp->b - 10;
 	      if ((int) strlen (optable[i].in) == len
@@ -4699,7 +4699,7 @@
 	}
       else
 	{
-	  for (i = 0; i < ARRAY_SIZE (optable); i++)
+	  for (i = 0; i < (size_t)ARRAY_SIZE (optable); i++)
 	    {
 	      int len = declp->p - declp->b - 3;
 	      if ((int) strlen (optable[i].in) == len
@@ -4747,7 +4747,7 @@
       if (declp->b[4] == '\0')
 	{
 	  /* Operator.  */
-	  for (i = 0; i < ARRAY_SIZE (optable); i++)
+	  for (i = 0; i < (size_t)ARRAY_SIZE (optable); i++)
 	    {
 	      if (strlen (optable[i].in) == 2
 		  && memcmp (optable[i].in, declp->b + 2, 2) == 0)
@@ -4764,7 +4764,7 @@
 	  if (declp->b[2] == 'a' && declp->b[5] == '\0')
 	    {
 	      /* Assignment.  */
-	      for (i = 0; i < ARRAY_SIZE (optable); i++)
+	      for (i = 0; i < (size_t)ARRAY_SIZE (optable); i++)
 		{
 		  if (strlen (optable[i].in) == 3
 		      && memcmp (optable[i].in, declp->b + 2, 3) == 0)
diff --git a/coregrind/vg_errcontext.c b/coregrind/vg_errcontext.c
index 5092152..8b953d7 100644
--- a/coregrind/vg_errcontext.c
+++ b/coregrind/vg_errcontext.c
@@ -204,7 +204,7 @@
 
 void VG_(gen_suppression)(Error* err)
 {
-   UInt        i;
+   Int         i;
    UChar       buf[M_VG_ERRTXT];
    ExeContext* ec      = VG_(get_error_where)(err);
    Int         stop_at = VG_(clo_backtrace_size);
diff --git a/coregrind/vg_from_ucode.c b/coregrind/vg_from_ucode.c
index db3d8bd..b285e1d 100644
--- a/coregrind/vg_from_ucode.c
+++ b/coregrind/vg_from_ucode.c
@@ -164,7 +164,7 @@
                      histogram[i].counts, count_pc, 
                      avg_size, size_pc);
 
-         for (j = 0; j < size_pc; j++) VG_(printf)("O");
+         for (j = 0; j < (Int)size_pc; j++) VG_(printf)("O");
          VG_(printf)("\n");
 
       } else {
@@ -1883,7 +1883,7 @@
  * Searches through compacts first, then non-compacts. */
 Int VG_(helper_offset)(Addr a)
 {
-   Int i;
+   UInt i;
    Char buf[100];
 
    for (i = 0; i < VG_(n_compact_helpers); i++)
diff --git a/coregrind/vg_intercept.c b/coregrind/vg_intercept.c
index 1d99d33..1f810e8 100644
--- a/coregrind/vg_intercept.c
+++ b/coregrind/vg_intercept.c
@@ -266,8 +266,8 @@
 
 int VGR_(poll) (struct pollfd *__fds, nfds_t __nfds, int __timeout)
 {
-   unsigned int        ms_now, ms_end;
-   int                 res, i;
+   unsigned int        ms_now, ms_end, i;
+   int                 res;
    struct vki_timespec nanosleep_interval;
 
    __my_pthread_testcancel();
diff --git a/coregrind/vg_main.c b/coregrind/vg_main.c
index 2331ec2..960fa75 100644
--- a/coregrind/vg_main.c
+++ b/coregrind/vg_main.c
@@ -177,10 +177,12 @@
 }
 
 /* Allocate offsets in baseBlock for the skin helpers */
-static void assign_helpers_in_baseBlock(UInt n, Int offsets[], Addr addrs[])
+static 
+void assign_helpers_in_baseBlock(UInt n, Int offsets[], Addr addrs[])
 {
-   Int i;
-   for (i = 0; i < n; i++) offsets[i] = alloc_BaB_1_set( addrs[i] );
+   UInt i;
+   for (i = 0; i < n; i++) 
+      offsets[i] = alloc_BaB_1_set( addrs[i] );
 }
 
 Bool VG_(need_to_handle_esp_assignment)(void)
@@ -708,7 +710,7 @@
 static void process_cmd_line_options ( void )
 {
    Char* argv[M_VG_CMDLINE_OPTS];
-   UInt  argc;
+   Int   argc;
    Char* p;
    Char* str;
    Int   i, eventually_logfile_fd, ctr;
@@ -732,7 +734,7 @@
       envc & envp. It is not fool-proof, but these structures should
       change less often than the libc ones. */
    {
-       UInt* sp;
+       Int* sp;
 
        /* Look for the stack segment by parsing /proc/self/maps and
 	  looking for a section bracketing VG_(esp_at_startup) which
diff --git a/coregrind/vg_malloc2.c b/coregrind/vg_malloc2.c
index bf9c8d0..9b6af79 100644
--- a/coregrind/vg_malloc2.c
+++ b/coregrind/vg_malloc2.c
@@ -629,8 +629,9 @@
 static
 void splitChunk ( Arena* a, UInt* b, Int b_listno, UInt req_bszW )
 {
-   Int b_bszW, frag_bszW;
-   b_bszW = mk_plain_bszW(get_bszW_lo(b));
+   UInt b_bszW;
+   Int  frag_bszW;
+   b_bszW = (UInt)mk_plain_bszW(get_bszW_lo(b));
    vg_assert(req_bszW < b_bszW);
    frag_bszW = b_bszW - req_bszW;
    vg_assert(frag_bszW >= overhead_szW(a));
diff --git a/coregrind/vg_mylibc.c b/coregrind/vg_mylibc.c
index b81e36c..ef06526 100644
--- a/coregrind/vg_mylibc.c
+++ b/coregrind/vg_mylibc.c
@@ -168,7 +168,7 @@
    Int i;
    vg_assert(set != NULL);
    for (i = 0; i < VKI_KNSIG_WORDS; i++)
-      if (set->ws[i] != ~0x0) return False;
+      if (set->ws[i] != (UInt)(~0x0)) return False;
    return True;
 }
 
@@ -664,7 +664,7 @@
 /* A general replacement for sprintf(). */
 UInt VG_(sprintf) ( Char* buf, Char *format, ... )
 {
-   UInt ret;
+   Int ret;
    va_list vargs;
    Char *ptr = buf;
    static void add_to_vg_sprintf_buf ( Char c )
@@ -753,15 +753,18 @@
    vg_assert(base >= 2 && base <= 36);
    if (*str == '-') { str++; neg = True; };
    while (True) {
-      if (*str >= '0' && *str <=('9' - (10 - base))) {
+      if (*str >= '0' 
+          && *str <= (Char)('9' - (10 - base))) {
          n = base*n + (Long)(*str - '0');
       }
       else 
-      if (base > 10 && *str >= 'A' && *str <= ('Z' - (36 - base))) {
+      if (base > 10 && *str >= 'A' 
+          && *str <= (Char)('Z' - (36 - base))) {
          n = base*n + (Long)((*str - 'A') + 10);
       }
       else 
-      if (base > 10 && *str >= 'a' && *str <= ('z' - (36 - base))) {
+      if (base > 10 && *str >= 'a' 
+          && *str <= (Char)('z' - (36 - base))) {
          n = base*n + (Long)((*str - 'a') + 10);
       }
       else {
diff --git a/coregrind/vg_replace_malloc.c b/coregrind/vg_replace_malloc.c
index 2299fad..28068c2 100644
--- a/coregrind/vg_replace_malloc.c
+++ b/coregrind/vg_replace_malloc.c
@@ -422,7 +422,7 @@
 struct mallinfo mallinfo ( void )
 {
    /* Should really try to return something a bit more meaningful */
-   Int             i;
+   UInt            i;
    struct mallinfo mi;
    UChar*          pmi = (UChar*)(&mi);
    for (i = 0; i < sizeof(mi); i++)
diff --git a/coregrind/vg_scheduler.c b/coregrind/vg_scheduler.c
index 04c4933..ed4fcba 100644
--- a/coregrind/vg_scheduler.c
+++ b/coregrind/vg_scheduler.c
@@ -125,7 +125,7 @@
       /* File descriptor waited for.  -1 means this slot is not in use */
       Int      fd;
       /* The syscall number the fd is used in. */
-      Int      syscall_no;
+      UInt     syscall_no;
 
       /* False => still waiting for select to tell us the fd is ready
          to go.  True => the fd is ready, but the results have not yet
@@ -1134,7 +1134,8 @@
 static
 void complete_blocked_syscalls ( void )
 {
-   Int      fd, i, res, syscall_no;
+   Int      fd, i, res;
+   UInt     syscall_no;
    void*    pre_res;
    ThreadId tid;
    Char     msg_buf[100];
@@ -1200,7 +1201,8 @@
 static
 void check_for_pthread_cond_timedwait ( void )
 {
-   Int i, now;
+   Int  i;
+   UInt now;
    for (i = 1; i < VG_N_THREADS; i++) {
       if (VG_(threads)[i].status != VgTs_WaitCV)
          continue;
@@ -3621,7 +3623,7 @@
          /* 1 */ vg_assert(mx != NULL);
 	 /* 2 */ vg_assert(mx->__m_count > 0);
          /* 3 */ vg_assert(VG_(is_valid_tid)((ThreadId)mx->__m_owner));
-         /* 4 */ vg_assert(i != (ThreadId)mx->__m_owner); 
+         /* 4 */ vg_assert((UInt)i != (ThreadId)mx->__m_owner); 
       } else 
       if (VG_(threads)[i].status == VgTs_WaitCV) {
          vg_assert(cv != NULL);
diff --git a/coregrind/vg_symtab2.c b/coregrind/vg_symtab2.c
index 304e9b9..3de0293 100644
--- a/coregrind/vg_symtab2.c
+++ b/coregrind/vg_symtab2.c
@@ -161,7 +161,8 @@
    static SegInfo* curr_si = NULL;
 
    Char* new_tab;
-   Int   new_sz, i, space_needed;
+   Int   space_needed, i;
+   UInt  new_sz, u;
 
    /* Avoid gratuitous duplication:  if we saw `str' within the last NN,
     * within this segment, return that index.  Saves about 200KB in glibc,
@@ -192,8 +193,8 @@
       if (new_sz == 0) new_sz = 5000;
       new_tab = VG_(arena_malloc)(VG_AR_SYMTAB, new_sz);
       if (si->strtab != NULL) {
-         for (i = 0; i < si->strtab_used; i++)
-            new_tab[i] = si->strtab[i];
+         for (u = 0; u < si->strtab_used; u++)
+            new_tab[u] = si->strtab[u];
          VG_(arena_free)(VG_AR_SYMTAB, si->strtab);
       }
       si->strtab      = new_tab;
@@ -214,7 +215,7 @@
 static __inline__
 void addSym ( SegInfo* si, RiSym* sym )
 {
-   Int    new_sz, i;
+   UInt   new_sz, i;
    RiSym* new_tab;
 
    /* Ignore zero-sized syms. */
@@ -243,7 +244,7 @@
 static __inline__
 void addLoc ( SegInfo* si, RiLoc* loc )
 {
-   Int    new_sz, i;
+   UInt   new_sz, i;
    RiLoc* new_tab;
 
    /* Zero-sized locs should have been ignored earlier */
@@ -482,7 +483,7 @@
    /* Detect and "fix" overlapping address ranges. */
    n_truncated = 0;
 
-   for (i = 0; i < si->symtab_used-1; i++) {
+   for (i = 0; i < ((Int)si->symtab_used) -1; i++) {
 
       vg_assert(si->symtab[i].addr <= si->symtab[i+1].addr);
 
@@ -529,7 +530,7 @@
       /* It may be that the i+1 entry now needs to be moved further
          along to maintain the address order requirement. */
       j = i+1;
-      while (j < si->symtab_used-1 
+      while (j < ((Int)si->symtab_used)-1 
              && si->symtab[j].addr > si->symtab[j+1].addr) {
          SWAP(RiSym,si->symtab[j],si->symtab[j+1]);
          j++;
@@ -540,7 +541,7 @@
    if (n_truncated > 0) goto cleanup_more;
 
    /* Ensure relevant postconditions hold. */
-   for (i = 0; i < si->symtab_used-1; i++) {
+   for (i = 0; i < ((Int)si->symtab_used)-1; i++) {
       /* No zero-sized symbols. */
       vg_assert(si->symtab[i].size > 0);
       /* In order. */
@@ -598,7 +599,7 @@
    }
 
    /* If two adjacent entries overlap, truncate the first. */
-   for (i = 0; i < si->loctab_used-1; i++) {
+   for (i = 0; i < ((Int)si->loctab_used)-1; i++) {
       vg_assert(si->loctab[i].size < 10000);
       if (si->loctab[i].addr + si->loctab[i].size > si->loctab[i+1].addr) {
          /* Do this in signed int32 because the actual .size fields
@@ -618,7 +619,7 @@
    /* Zap any zero-sized entries resulting from the truncation
       process. */
    j = 0;
-   for (i = 0; i < si->loctab_used; i++) {
+   for (i = 0; i < (Int)si->loctab_used; i++) {
       if (si->loctab[i].size > 0) {
          si->loctab[j] = si->loctab[i];
          j++;
@@ -627,7 +628,7 @@
    si->loctab_used = j;
 
    /* Ensure relevant postconditions hold. */
-   for (i = 0; i < si->loctab_used-1; i++) {
+   for (i = 0; i < ((Int)si->loctab_used)-1; i++) {
       /* 
       VG_(printf)("%d   (%d) %d 0x%x\n", 
                    i, si->loctab[i+1].confident, 
@@ -1102,7 +1103,7 @@
          break;
        }
 
-      if (info.li_length + sizeof (external->li_length) > dwarf2_sz)
+      if (info.li_length + sizeof (external->li_length) > (UInt)dwarf2_sz)
        {
         vg_symerr("DWARF line info appears to be corrupt "
                   "- the section is too small");
@@ -1393,7 +1394,7 @@
    Int           i;
    Bool          ok;
    Addr          oimage;
-   Int           n_oimage;
+   UInt          n_oimage;
    struct vki_stat stat_buf;
 
    oimage = (Addr)NULL;
@@ -1645,7 +1646,7 @@
 
          /* Perhaps should start at i = 1; ELF docs suggest that entry
             0 always denotes `unknown symbol'. */
-         for (i = 1; i < o_symtab_sz/sizeof(Elf32_Sym); i++){
+         for (i = 1; i < (Int)(o_symtab_sz/sizeof(Elf32_Sym)); i++){
 #           if 1
 	    if (VG_(clo_trace_symtab)) {
 	       VG_(printf)("raw symbol [%d]: ", i);
@@ -2149,7 +2150,7 @@
       len = VG_(sprintf)(buf2, "%c%d",
 			 offset < 0 ? '-' : '+',
 			 offset < 0 ? -offset : offset);
-      vg_assert(len < sizeof(buf2));
+      vg_assert(len < (Int)sizeof(buf2));
 
       if (len < (end - symend)) {
 	 Char *cp = buf2;
@@ -2342,7 +2343,7 @@
       VG_(message)(Vg_UserMsg, "%s", buf);
       i++;
 
-   } while (i < stop_at && ec->eips[i] != 0);
+   } while (i < (UInt)stop_at && ec->eips[i] != 0);
 }
 
 #undef APPEND
diff --git a/coregrind/vg_syscalls.c b/coregrind/vg_syscalls.c
index 00786ba..57ef09e 100644
--- a/coregrind/vg_syscalls.c
+++ b/coregrind/vg_syscalls.c
@@ -1363,7 +1363,7 @@
          MAYBE_PRINTF("close ( %d )\n",arg1);
          /* Detect and negate attempts by the client to close Valgrind's
             logfile fd ... */
-         if (arg1 == VG_(clo_logfile_fd)) {
+         if (arg1 == (UInt)VG_(clo_logfile_fd)) {
             VG_(message)(Vg_UserMsg, 
               "Warning: client attempted to close "
                "Valgrind's logfile fd (%d).", 
@@ -2655,7 +2655,7 @@
                            arg1, arg2 * sizeof(struct pollfd) );
          KERNEL_DO_SYSCALL(tid,res);
          if (!VG_(is_kerror)(res) && res > 0) {
-            Int i;
+            UInt i;
             struct pollfd * arr = (struct pollfd *)arg1;
             for (i = 0; i < arg2; i++)
                VG_TRACK( post_mem_write, (Addr)(&arr[i].revents), 
diff --git a/coregrind/vg_translate.c b/coregrind/vg_translate.c
index 56f94b0..0010807 100644
--- a/coregrind/vg_translate.c
+++ b/coregrind/vg_translate.c
@@ -1662,7 +1662,7 @@
    UInstr*     u;
    Int         delta = 0;
    UInt        t_ESP = INVALID_TEMPREG;
-   UInt        i;
+   Int         i;
 
    cb = VG_(setup_UCodeBlock)(cb_in);
 
diff --git a/coregrind/vg_transtab.c b/coregrind/vg_transtab.c
index 5c33fab..c35cdcf 100644
--- a/coregrind/vg_transtab.c
+++ b/coregrind/vg_transtab.c
@@ -599,7 +599,7 @@
          /* make sure no other blocks chain to the one we just discarded */
          for(j = 0; j < VG_TC_N_SECTORS; j++) {
             if (vg_tc[j] != NULL)
-               unchain_sector(j, tce->payload, tce->trans_size);
+               unchain_sector(j, (Addr)tce->payload, tce->trans_size);
          }
       }