Token.c appears to have a bug.

jw schultz jw at pegasys.ws
Tue Oct 14 09:54:20 EST 2003


On Mon, Oct 13, 2003 at 04:43:45PM -0700, Wayne Davison wrote:
> On Mon, Oct 13, 2003 at 07:29:24PM -0400, John E. Malmberg wrote:
> > Or should there be parenthesis around (n >> 8) to make sure that it
> > happens before the most significant part of "n" is discarded?
> 
> Yes, there should be parens there.  Note that this bug only affects
> batch mode (a fairly rare option).  Thanks for pointing this out.
> I'll check in a fix in a moment.

Having looked at that bit of code now.  I am a bit concerned
about the use of shift operators on signed integers here.
Habit also makes me shy of relying on char being 8 bits but
that is probably overcautious.



Index: token.c
===================================================================
RCS file: /data/cvs/rsync/token.c,v
retrieving revision 1.27
diff -u -r1.27 token.c
--- token.c	11 Sep 2003 04:48:09 -0000	1.27
+++ token.c	13 Oct 2003 23:47:50 -0000
@@ -160,7 +160,7 @@
 	int n, r;
 	static int init_done, flush_pending;
 	extern int write_batch;
-	char temp_byte;
+	unsigned char temp_byte;
 
 	if (last_token == -1) {
 		/* initialization */
@@ -211,7 +211,7 @@
 			write_byte(f, n >> 8);
 			if (write_batch) {
 				write_batch_delta_file((char *)&n,sizeof(char));
-				temp_byte = (char) n >> 8;
+				temp_byte = (unsigned char) (n >> 8 & 0xFF);
 				write_batch_delta_file(&temp_byte,sizeof(temp_byte));
 			}
 		}

-- 
________________________________________________________________
	J.W. Schultz            Pegasystems Technologies
	email address:		jw at pegasys.ws

		Remember Cernan and Schmitt



More information about the rsync mailing list