Skip to content

Commit ed95425

Browse files
Apply suggestions from code review
Co-authored-by: c-jimenez <[email protected]>
1 parent e42a42a commit ed95425

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/websockets/libwebsockets/LibWebsocketServer.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,9 @@ int LibWebsocketServer::eventCallback(struct lws* wsi, enum lws_callback_reasons
312312
if (strcmp("websocket", static_cast<char*>(in)) == 0)
313313
{
314314
// Check URI
315-
char* uri = new char[lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI) + 1];
316-
int uri_len = lws_hdr_copy(wsi, uri, sizeof(uri), WSI_TOKEN_GET_URI);
315+
const size_t uri_size = lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI) + 1;
316+
char* uri = new char[uri_size];
317+
int uri_len = lws_hdr_copy(wsi, uri, uri_size, WSI_TOKEN_GET_URI);
317318
if ((uri_len >= static_cast<int>(server->m_url.path().size())) &&
318319
(strncmp(uri, server->m_url.path().c_str(), server->m_url.path().size()) == 0))
319320
{
@@ -439,8 +440,9 @@ int LibWebsocketServer::eventCallback(struct lws* wsi, enum lws_callback_reasons
439440
server->m_clients[wsi] = client;
440441

441442
// Notify connection
442-
char* uri = new char[lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI) + 1];
443-
if (lws_hdr_copy(wsi, uri, sizeof(uri), WSI_TOKEN_GET_URI) <= 0)
443+
const size_t uri_size = lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI) + 1;
444+
char* uri = new char[uri_size];
445+
if (lws_hdr_copy(wsi, uri, uri_size, WSI_TOKEN_GET_URI) <= 0)
444446
{
445447
uri[0] = 0;
446448
}

0 commit comments

Comments
 (0)