shithub: rd

Download patch

ref: e58a3be61ffb1702eb5a3765be4610c2a0e049fb
parent: 3befb91804e0aa9022b694c38c33cec0791d9df9
author: Yaroslav Kolomiiets <yarikos@gmail.com>
date: Wed Jan 23 04:06:35 EST 2019

refactor getsnarf

--- a/wsys.c
+++ b/wsys.c
@@ -104,12 +104,13 @@
 	i = 0;
 	seek(snarffd, 0, 0);
 	while((n = read(snarffd, buf, sizeof(buf))) > 0){
-		s = erealloc(s, i+n+1);
+		s = erealloc(s, i+n+1);	// an extra byte for the terminating zero
 		memmove(s+i, buf, n);
 		i += n;
-		s[i] = 0;
 	}
-	*pnb = i+1;	// for terminating zero
+	s[i] = 0;
+	i++;
+	*pnb = i;
 	return s;
 }