damn, I had implicitly assumed signed characters when writing the
authorAndrew Tridgell <tridge@samba.org>
Mon, 15 Dec 1997 12:37:40 +0000 (12:37 +0000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 15 Dec 1997 12:37:40 +0000 (12:37 +0000)
rolling checksum code. The result is that rsync worked much more
slowly when going between two machines where one of the machines uses
signed and the other unsigned chars. The rolling checksum rarely
matched so effectively a copy was done in many cases. The data always
came through correctly so no file corruption occurred but it's pretty
pointless using rsync if it doesn't speed things up!
I've now made the sign of the chars explicit

checksum.c
match.c

index 2015836..7b8035c 100644 (file)
@@ -30,10 +30,11 @@ extern int remote_version;
   a simple 32 bit checksum that can be upadted from either end
   (inspired by Mark Adler's Adler-32 checksum)
   */
-uint32 get_checksum1(char *buf,int len)
+uint32 get_checksum1(char *buf1,int len)
 {
     int i;
     uint32 s1, s2;
+    signed char *buf = (signed char *)buf1;
 
     s1 = s2 = 0;
     for (i = 0; i < (len-4); i+=4) {
diff --git a/match.c b/match.c
index 591558f..a353c83 100644 (file)
--- a/match.c
+++ b/match.c
@@ -130,16 +130,16 @@ static void hash_search(int f,struct sum_struct *s,
   int end;
   char sum2[SUM_LENGTH];
   uint32 s1, s2, sum; 
-  char *map;
+  signed char *map;
 
   if (verbose > 2)
     fprintf(FERROR,"hash search b=%d len=%d\n",s->n,(int)len);
 
   k = MIN(len, s->n);
 
-  map = map_ptr(buf,0,k);
+  map = (signed char *)map_ptr(buf,0,k);
 
-  sum = get_checksum1(map, k);
+  sum = get_checksum1((char *)map, k);
   s1 = sum & 0xFFFF;
   s2 = sum >> 16;
   if (verbose > 3)
@@ -175,16 +175,16 @@ static void hash_search(int f,struct sum_struct *s,
 
          if (!done_csum2) {
            int l = MIN(s->n,len-offset);
-           map = map_ptr(buf,offset,l);
-           get_checksum2(map,l,sum2);
+           map = (signed char *)map_ptr(buf,offset,l);
+           get_checksum2((char *)map,l,sum2);
            done_csum2 = 1;
          }
          if (memcmp(sum2,s->sums[i].sum2,csum_length) == 0) {
            matched(f,s,buf,len,offset,i);
            offset += s->sums[i].len - 1;
            k = MIN((len-offset), s->n);
-           map = map_ptr(buf,offset,k);
-           sum = get_checksum1(map, k);
+           map = (signed char *)map_ptr(buf,offset,k);
+           sum = get_checksum1((char *)map, k);
            s1 = sum & 0xFFFF;
            s2 = sum >> 16;
            ++matches;
@@ -198,7 +198,7 @@ static void hash_search(int f,struct sum_struct *s,
     }
 
     /* Trim off the first byte from the checksum */
-    map = map_ptr(buf,offset,k+1);
+    map = (signed char *)map_ptr(buf,offset,k+1);
     s1 -= map[0] + CHAR_OFFSET;
     s2 -= k * (map[0]+CHAR_OFFSET);