about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-10-27 10:33:56 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-10-27 10:33:56 -0700
commit5f4ccccbe72c031383cc5e69b1546d372ed151f0 (patch)
treec6d010ef438ab21644a1b0e8aa74315e512259b6
parent72855698f5ef082b89c2a53b435c4b31495da277 (diff)
downloadmu-5f4ccccbe72c031383cc5e69b1546d372ed151f0.tar.gz
3600 - allow reading a single byte from a socket
Required fixing an off-by-one error.

(Not bothering writing a test for this since I'm hoping to simplify
$read-from-socket to always return a single character..)
-rw-r--r--091socket.cc6
1 files changed, 3 insertions, 3 deletions
diff --git a/091socket.cc b/091socket.cc
index 51790bdf..e268a022 100644
--- a/091socket.cc
+++ b/091socket.cc
@@ -261,10 +261,10 @@ case _READ_FROM_SOCKET: {
     socket->polled = true;
   }
   int bytes = static_cast<int>(ingredients.at(1).at(0));
-  char* contents = new char[bytes];
-  bzero(contents, bytes);
+  char* contents = new char[bytes+/*terminal null*/1];
+  bzero(contents, bytes+/*terminal null*/1);
   int error_code = 0;
-  int bytes_read = recv(socket->fd, contents, bytes-/*terminal null*/1, MSG_DONTWAIT);
+  int bytes_read = recv(socket->fd, contents, bytes, MSG_DONTWAIT);
   if (bytes_read < 0) error_code = errno;
 //?   if (error_code) {
 //?     ostringstream out;