Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -Werror -Wshadow compiler flags to CMAKE_CXX_FLAGS (#531) #535

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
72 changes: 36 additions & 36 deletions ixwebsocket/IXHttpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpResponse>(code,
description,
errorCode,
headers,
payload,
ss.str(),
errSs.str(),
uploadSize,
downloadSize);
}
Expand All @@ -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<HttpResponse>(code,
description,
errorCode,
headers,
payload,
errorMsg,
msg,
uploadSize,
downloadSize);
}
Expand All @@ -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<HttpResponse>(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<HttpResponse>(code,
description,
HttpErrorCode::MissingStatus,
headers,
payload,
errorMsg,
msg,
uploadSize,
downloadSize);
}
Expand All @@ -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<HttpResponse>(code,
description,
errorCode,
headers,
payload,
errorMsg,
msg,
uploadSize,
downloadSize);
}
Expand All @@ -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<HttpResponse>(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<HttpResponse>(code,
description,
HttpErrorCode::TooManyRedirects,
headers,
payload,
ss.str(),
maxRedirectSs.str(),
uploadSize,
downloadSize);
}
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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<HttpResponse>(code,
description,
errorCode,
errCode,
headers,
payload,
errorMsg,
Expand All @@ -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<HttpResponse>(code,
description,
errorCode,
errCode,
headers,
payload,
errorMsg,
Expand All @@ -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<HttpResponse>(code,
description,
HttpErrorCode::CannotReadBody,
headers,
payload,
errorMsg,
msg,
uploadSize,
downloadSize);
}
Expand All @@ -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<HttpResponse>(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<HttpResponse>(code,
description,
HttpErrorCode::Gzip,
headers,
payload,
errorMsg,
msg,
uploadSize,
downloadSize);
#endif
Expand Down
1 change: 0 additions & 1 deletion ixwebsocket/IXHttpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ namespace ix
if (std::get<0>(ret))
{
auto request = std::get<2>(ret);
std::shared_ptr<ix::HttpResponse> response;
if (request->headers["Upgrade"] == "websocket")
{
WebSocketServer::handleUpgrade(std::move(socket), connectionState, request);
Expand Down
18 changes: 9 additions & 9 deletions ixwebsocket/IXWebSocketHandshake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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] = {};
Expand Down
2 changes: 1 addition & 1 deletion ixwebsocket/IXWebSocketTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ namespace ix
{
ssize_t ret = 0;
{
std::lock_guard<std::mutex> lock(_socketMutex);
std::lock_guard<std::mutex> socketLock(_socketMutex);
ret = _socket->send((char*) &_txbuf[0], _txbuf.size());
}

Expand Down
2 changes: 1 addition & 1 deletion ws/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down