13
0

WebSockets: use lws_strncpy() when available

This commit is contained in:
Luciano Iam 2020-04-10 08:26:22 +02:00 committed by Robin Gareus
parent 731ea79028
commit c477a81a7c
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04

View File

@ -389,9 +389,12 @@ WebsocketsServer::send_index_body (Client wsi)
std::string index = _resources.scan ();
char body[MAX_INDEX_SIZE];
//lws_strncpy (body, index.c_str (), sizeof(body));
#if LWS_LIBRARY_VERSION_MAJOR >= 3
lws_strncpy (body, index.c_str (), sizeof(body));
#else
memset (body, 0, sizeof (body));
strncpy (body, index.c_str (), sizeof(body) - 1);
#endif
int len = strlen (body);
if (lws_write (wsi, reinterpret_cast<unsigned char*> (body), len, LWS_WRITE_HTTP) != len) {