diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e64573b..673f9724 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") endif() if (UNIX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -Wshadow -Wunused -pedantic") endif() if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") diff --git a/ixwebsocket/IXHttpClient.cpp b/ixwebsocket/IXHttpClient.cpp index 871be336..9b55f12c 100644 --- a/ixwebsocket/IXHttpClient.cpp +++ b/ixwebsocket/IXHttpClient.cpp @@ -264,14 +264,14 @@ namespace ix if (!success) { auto errorCode = args->cancel ? HttpErrorCode::Cancelled : HttpErrorCode::CannotConnect; - std::stringstream ss; - ss << "Cannot connect to url: " << url << " / error : " << errMsg; + std::stringstream errSs; + errSs << "Cannot connect to url: " << url << " / error : " << errMsg; return std::make_shared(code, description, errorCode, headers, payload, - ss.str(), + errSs.str(), uploadSize, downloadSize); } @@ -281,27 +281,27 @@ namespace ix if (args->verbose) { - std::stringstream ss; - ss << "Sending " << verb << " request " + std::stringstream verboseSs; + verboseSs << "Sending " << verb << " request " << "to " << host << ":" << port << std::endl << "request size: " << req.size() << " bytes" << std::endl << "=============" << std::endl << req << "=============" << std::endl << std::endl; - log(ss.str(), args); + log(verboseSs.str(), args); } if (!_socket->writeBytes(req, isCancellationRequested)) { auto errorCode = args->cancel ? HttpErrorCode::Cancelled : HttpErrorCode::SendError; - std::string errorMsg("Cannot send request"); + std::string msg("Cannot send request"); return std::make_shared(code, description, errorCode, headers, payload, - errorMsg, + msg, uploadSize, downloadSize); } @@ -315,33 +315,33 @@ namespace ix if (!lineValid) { auto errorCode = args->cancel ? HttpErrorCode::Cancelled : HttpErrorCode::CannotReadStatusLine; - std::string errorMsg("Cannot retrieve status line"); + std::string msg("Cannot retrieve status line"); return std::make_shared(code, description, errorCode, headers, payload, - errorMsg, + msg, uploadSize, downloadSize); } if (args->verbose) { - std::stringstream ss; - ss << "Status line " << line; - log(ss.str(), args); + std::stringstream verboseSs; + verboseSs << "Status line " << line; + log(verboseSs.str(), args); } if (sscanf(line.c_str(), "HTTP/1.1 %d", &code) != 1) { - std::string errorMsg("Cannot parse response code from status line"); + std::string msg("Cannot parse response code from status line"); return std::make_shared(code, description, HttpErrorCode::MissingStatus, headers, payload, - errorMsg, + msg, uploadSize, downloadSize); } @@ -353,13 +353,13 @@ namespace ix if (!headersValid) { auto errorCode = args->cancel ? HttpErrorCode::Cancelled : HttpErrorCode::HeaderParsingError; - std::string errorMsg("Cannot parse http headers"); + std::string msg("Cannot parse http headers"); return std::make_shared(code, description, errorCode, headers, payload, - errorMsg, + msg, uploadSize, downloadSize); } @@ -369,27 +369,27 @@ namespace ix { if (headers.find("Location") == headers.end()) { - std::string errorMsg("Missing location header for redirect"); + std::string msg("Missing location header for redirect"); return std::make_shared(code, description, HttpErrorCode::MissingLocation, headers, payload, - errorMsg, + msg, uploadSize, downloadSize); } if (redirects >= args->maxRedirects) { - std::stringstream ss; - ss << "Too many redirects: " << redirects; + std::stringstream maxRedirectSs; + maxRedirectSs << "Too many redirects: " << redirects; return std::make_shared(code, description, HttpErrorCode::TooManyRedirects, headers, payload, - ss.str(), + maxRedirectSs.str(), uploadSize, downloadSize); } @@ -446,7 +446,7 @@ namespace ix else if (headers.find("Transfer-Encoding") != headers.end() && headers["Transfer-Encoding"] == "chunked") { - std::stringstream ss; + std::stringstream chunkSizeSs; while (true) { @@ -467,9 +467,9 @@ namespace ix } uint64_t chunkSize; - ss.str(""); - ss << std::hex << line; - ss >> chunkSize; + chunkSizeSs.str(""); + chunkSizeSs << std::hex << line; + chunkSizeSs >> chunkSize; if (args->verbose) { @@ -485,11 +485,11 @@ namespace ix isCancellationRequested); if (!chunkResult.first) { - auto errorCode = args->cancel ? HttpErrorCode::Cancelled : HttpErrorCode::ChunkReadError; + auto errCode = args->cancel ? HttpErrorCode::Cancelled : HttpErrorCode::ChunkReadError; errorMsg = "Cannot read chunk"; return std::make_shared(code, description, - errorCode, + errCode, headers, payload, errorMsg, @@ -508,10 +508,10 @@ namespace ix if (!lineResult.first) { - auto errorCode = args->cancel ? HttpErrorCode::Cancelled : HttpErrorCode::ChunkReadError; + auto errCode = args->cancel ? HttpErrorCode::Cancelled : HttpErrorCode::ChunkReadError; return std::make_shared(code, description, - errorCode, + errCode, headers, payload, errorMsg, @@ -528,13 +528,13 @@ namespace ix } else { - std::string errorMsg("Cannot read http body"); + std::string msg("Cannot read http body"); return std::make_shared(code, description, HttpErrorCode::CannotReadBody, headers, payload, - errorMsg, + msg, uploadSize, downloadSize); } @@ -548,25 +548,25 @@ namespace ix std::string decompressedPayload; if (!gzipDecompress(payload, decompressedPayload)) { - std::string errorMsg("Error decompressing payload"); + std::string msg("Error decompressing payload"); return std::make_shared(code, description, HttpErrorCode::Gzip, headers, payload, - errorMsg, + msg, uploadSize, downloadSize); } payload = decompressedPayload; #else - std::string errorMsg("ixwebsocket was not compiled with gzip support on"); + std::string msg("ixwebsocket was not compiled with gzip support on"); return std::make_shared(code, description, HttpErrorCode::Gzip, headers, payload, - errorMsg, + msg, uploadSize, downloadSize); #endif diff --git a/ixwebsocket/IXHttpServer.cpp b/ixwebsocket/IXHttpServer.cpp index 00456629..c6765718 100644 --- a/ixwebsocket/IXHttpServer.cpp +++ b/ixwebsocket/IXHttpServer.cpp @@ -97,7 +97,6 @@ namespace ix if (std::get<0>(ret)) { auto request = std::get<2>(ret); - std::shared_ptr response; if (request->headers["Upgrade"] == "websocket") { WebSocketServer::handleUpgrade(std::move(socket), connectionState, request); diff --git a/ixwebsocket/IXWebSocketHandshake.cpp b/ixwebsocket/IXWebSocketHandshake.cpp index 744e3ab7..02f25f8c 100644 --- a/ixwebsocket/IXWebSocketHandshake.cpp +++ b/ixwebsocket/IXWebSocketHandshake.cpp @@ -172,11 +172,11 @@ namespace ix // HTTP/1.0 is too old. if (httpVersion != "HTTP/1.1") { - std::stringstream ss; - ss << "Expecting HTTP/1.1, got " << httpVersion << ". " + std::stringstream httpVersionSs; + httpVersionSs << "Expecting HTTP/1.1, got " << httpVersion << ". " << "Rejecting connection to " << url << ", status: " << status << ", HTTP Status line: " << line; - return WebSocketInitResult(false, status, ss.str()); + return WebSocketInitResult(false, status, httpVersionSs.str()); } auto result = parseHttpHeaders(_socket, isCancellationRequested); @@ -192,11 +192,11 @@ namespace ix // a redirection (like 301) if (status != 101) { - std::stringstream ss; - ss << "Expecting status 101 (Switching Protocol), got " << status + std::stringstream statusSs; + statusSs << "Expecting status 101 (Switching Protocol), got " << status << " status connecting to " << url << ", HTTP Status line: " << line; - return WebSocketInitResult(false, status, ss.str(), headers, path); + return WebSocketInitResult(false, status, statusSs.str(), headers, path); } // Check the presence of the connection field @@ -214,9 +214,9 @@ namespace ix // if (!insensitiveStringCompare(headers["connection"], "Upgrade")) { - std::stringstream ss; - ss << "Invalid connection value: " << headers["connection"]; - return WebSocketInitResult(false, status, ss.str()); + std::stringstream connSs; + connSs << "Invalid connection value: " << headers["connection"]; + return WebSocketInitResult(false, status, connSs.str()); } char output[29] = {}; diff --git a/ixwebsocket/IXWebSocketTransport.cpp b/ixwebsocket/IXWebSocketTransport.cpp index f9d36c52..577c83e9 100644 --- a/ixwebsocket/IXWebSocketTransport.cpp +++ b/ixwebsocket/IXWebSocketTransport.cpp @@ -1062,7 +1062,7 @@ namespace ix { ssize_t ret = 0; { - std::lock_guard lock(_socketMutex); + std::lock_guard socketLock(_socketMutex); ret = _socket->send((char*) &_txbuf[0], _txbuf.size()); } diff --git a/ws/CMakeLists.txt b/ws/CMakeLists.txt index 98f15dee..163f44d8 100644 --- a/ws/CMakeLists.txt +++ b/ws/CMakeLists.txt @@ -8,7 +8,7 @@ project (ws) # There's -Weverything too for clang if (NOT WIN32) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -Wshadow -Wunused -pedantic") endif() set (CMAKE_CXX_STANDARD 11)