diff --git a/src/chat/misc.c b/src/chat/misc.c index acaa496..53f4b91 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -242,8 +242,9 @@ void why2_send_socket(char *text, char *username, int socket) char *text_copy = why2_calloc(length_buffer, sizeof(char)); struct json_object *json = json_tokener_parse("{}"); - //COPY text INTO text_copy WITHOUT LAST CHARACTER - strncpy(text_copy, text, length_buffer - 1); + //COPY text INTO text_copy (WITHOUT LAST CHARACTER WHEN NEWLINE IS AT THE END) + if (text[length_buffer - 1] == '\n') length_buffer--; + strncpy(text_copy, text, length_buffer); //ADD OBJECTS json_object_object_add(json, "message", json_object_new_string(text_copy));