receive whole message, do not trim at the first 0x00 v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Wed, 20 Apr 2022 20:59:42 +0200
branchv_0
changeset 6 65abb0376a0d
parent 5 c6ef2463e100
child 7 12e975f807ed
receive whole message, do not trim at the first 0x00
src/PosixMQ.h
--- a/src/PosixMQ.h	Wed Apr 20 02:26:44 2022 +0200
+++ b/src/PosixMQ.h	Wed Apr 20 20:59:42 2022 +0200
@@ -58,7 +58,8 @@
 		memset(buffer, 0, MSG_SIZE + 1);
 		ssize_t msgSize = mq_receive(handle, buffer, MSG_SIZE, nullptr);
 
-		if (msgSize >= 0) return std::string(buffer);
+		if (msgSize > sizeof (buffer))throw std::logic_error("Invalid PosixMQ message size.");
+		else if (msgSize >= 0) return std::string(buffer, msgSize);
 		else throw std::logic_error("Unable to receive PosixMQ message from " + queueName + " error: " + strerror(errno));
 	}