Browse Source

fixing memory issue causing undefined behaviour

logicp 5 years ago
parent
commit
9d138ecb5d
1 changed files with 6 additions and 4 deletions
  1. 6 4
      socket_listener.cpp

+ 6 - 4
socket_listener.cpp

@@ -1,14 +1,16 @@
+#include "headers/socket_listener.h"
+
 #include <arpa/inet.h>
 #include <netdb.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <sys/types.h>
 #include <unistd.h>
+
 #include <iostream>
 #include <string>
 
-#include <sys/socket.h>
 #include "headers/constants.h"
-#include "headers/socket_listener.h"
 
 int listening() { return socket(AF_INET, SOCK_STREAM, 0); }
 
@@ -53,8 +55,8 @@ void SocketListener::run() {
         if (bytesReceived > 0) {
           // TODO: Verify that we aren't producig undefined behaviour
           buffer_string += buf;
-          std::cout << "Received: " << buffer_string << std::endl;
-          onMessageReceived(socket, buffer_string);
+          std::cout << "Received: " << buf << std::endl;
+          onMessageReceived(socket, std::string(buf));
         } else {
           std::cout << "client disconnected" << std::endl;
           break;