[PATCH 2/3] Check return code for write when sending messages to server.

Thadeu Lima de Souza Cascardo cascardo en cascardo.info
Sab Mar 15 19:31:44 UTC 2014


This not only avoids a warning, but prevents us from moving forward,
when we should report an error, when write fails.
---
 rnetclient.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/rnetclient.c b/rnetclient.c
index d264c72..04869fd 100644
--- a/rnetclient.c
+++ b/rnetclient.c
@@ -161,8 +161,12 @@ static int handshake(int c)
 	char buffer[16];
 	int r;
 	buffer[0] = 1;
-	write(c, buffer, 1);
-	write(c, "00000000000000", 14);
+	r = write(c, buffer, 1);
+	if (r < 1)
+		return -1;
+	r = write(c, "00000000000000", 14);
+	if (r < 14)
+		return -1;
 	r = read(c, buffer, 1);
 	if (r != 1 && buffer[0] != 'E')
 		return -1;
-- 
1.8.1.4



Más información sobre la lista de distribución Softwares-impostos