X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/fb01d1fb07f6efd3752ff895fe8a77e26a2b2055..886df221c1ce1660a2b6cd274b13952b482fe5bf:/match.c diff --git a/match.c b/match.c index a3659fc6..0d4cfeb1 100644 --- a/match.c +++ b/match.c @@ -23,8 +23,10 @@ extern int checksum_seed; extern int append_mode; +extern int checksum_len; int updating_basis_file; +char sender_file_sum[MAX_DIGEST_LEN]; static int false_alarms; static int hash_hits; @@ -327,9 +329,6 @@ static void hash_search(int f,struct sum_struct *s, **/ void match_sums(int f, struct sum_struct *s, struct map_struct *buf, OFF_T len) { - char file_sum[MAX_DIGEST_LEN]; - int sum_len; - last_match = 0; false_alarms = 0; hash_hits = 0; @@ -377,18 +376,28 @@ void match_sums(int f, struct sum_struct *s, struct map_struct *buf, OFF_T len) matched(f, s, buf, len, -1); } - sum_len = sum_end(file_sum); - /* If we had a read error, send a bad checksum. */ - if (buf && buf->status != 0) - file_sum[0]++; + if (sum_end(sender_file_sum) != checksum_len) + overflow_exit("checksum_len"); /* Impossible... */ + + /* If we had a read error, send a bad checksum. We use all bits + * off as long as the checksum doesn't happen to be that, in + * which case we turn the last 0 bit into a 1. */ + if (buf && buf->status != 0) { + int i; + for (i = 0; i < checksum_len && sender_file_sum[i] == 0; i++) {} + memset(sender_file_sum, 0, checksum_len); + if (i == checksum_len) + sender_file_sum[i-1]++; + } if (DEBUG_GTE(CHKSUM, 2)) rprintf(FINFO,"sending file_sum\n"); - write_buf(f, file_sum, sum_len); + write_buf(f, sender_file_sum, checksum_len); - if (DEBUG_GTE(CHKSUM, 2)) + if (DEBUG_GTE(CHKSUM, 2)) { rprintf(FINFO, "false_alarms=%d hash_hits=%d matches=%d\n", false_alarms, hash_hits, matches); + } total_hash_hits += hash_hits; total_false_alarms += false_alarms;