1.1 --- a/c++/domain-socket-bridge/domain-socket-bridge.cpp Sun Nov 20 21:00:47 2016 +0100
1.2 +++ b/c++/domain-socket-bridge/domain-socket-bridge.cpp Mon Nov 21 22:48:29 2016 +0100
1.3 @@ -148,10 +148,11 @@
1.4 struct event_base *base = bufferevent_get_base(bev);
1.5
1.6 size_t len = evbuffer_get_length(input);
1.7 - char *data = (char*) malloc(len);
1.8 + char *data = (char*) malloc(len + 1);
1.9 + data[len] = 0; // as a string must be terminated by \0
1.10 evbuffer_copyout(input, data, len);
1.11
1.12 -
1.13 + //TODO: there might already be \0 in the byte stream, only the part before the first \0 will be formatted as a string
1.14 string dataFormated(data);
1.15 dataFormated = regex_replace(dataFormated, regex("\\n"), "\\n");
1.16 printf("%4d %8s '%s'\n", connectionId, "IN", dataFormated.c_str());