shithub: ridefs

Download patch

ref: 7935549c0acf1cc05dc6cc849df60caf3dbab945
parent: afca582f4b836d8dfa1ffd3ce55bb173428c9f65
author: x <x@hilbert>
date: Sun Aug 10 09:33:31 EDT 2025

Properly handle messages longer than 127 bytes

--- a/ridefs.c
+++ b/ridefs.c
@@ -243,9 +243,8 @@
 long
 writecmd(int fd, int cmd, ...){
 	va_list v;
-	char *j, *s;
-	long n;
-	char **strv;
+	char *j, *s, **strv, sz[4];
+	u32int n;
 	int i, strc;
 
 	j = nil;
@@ -274,12 +273,12 @@
 	}
 
 	n = 8 + strlen(s);
-	fprint(fd, "%c%c%c%cRIDE%s",
-		(char)(24>>n & 0xff),
-		(char)(16>>n & 0xff),
-		(char)(8>>n & 0xff),
-		(char)(n & 0xff),
-		s);
+	sz[0] = (n>>24) & 0xff;
+	sz[1] = (n>>16) & 0xff;
+	sz[2] = (n>> 8) & 0xff;
+	sz[3] =  n      & 0xff;
+	write(fd, sz, sizeof(sz));
+	fprint(fd, "RIDE%s", s);
 
 	if(debug)
 		fprint(2, "ridefs: T: %s\n", s);
--- a/test
+++ b/test
@@ -3,6 +3,7 @@
 fn fail{ >[1=2] echo $1 >[1=2]; exit $1 }
 
 argv0=$0
+~ $#1 0 || rideaddr=$1
 ~ $rideaddr '' && {
 	fail 'missing server address argument'
 }
@@ -76,7 +77,7 @@
 				cont=0
 			}
 		}
-		~ $rx '0 1 2 3 4' ||
+		~ $rx '1 2 3 4 5' ||
 			fail 'Did not receive expected response'
 	}
 	cd ..
--