Skip to content

Commit 56e0303

Browse files
committed
Add -Werror -Wshadow compiler flags to CMAKE_CXX_FLAGS (#531)
1 parent fb5a1f0 commit 56e0303

6 files changed

+48
-49
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
2020
endif()
2121

2222
if (UNIX)
23-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
23+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -Wshadow -Wunused -pedantic")
2424
endif()
2525

2626
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")

ixwebsocket/IXHttpClient.cpp

+36-36
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,14 @@ namespace ix
264264
if (!success)
265265
{
266266
auto errorCode = args->cancel ? HttpErrorCode::Cancelled : HttpErrorCode::CannotConnect;
267-
std::stringstream ss;
268-
ss << "Cannot connect to url: " << url << " / error : " << errMsg;
267+
std::stringstream errSs;
268+
errSs << "Cannot connect to url: " << url << " / error : " << errMsg;
269269
return std::make_shared<HttpResponse>(code,
270270
description,
271271
errorCode,
272272
headers,
273273
payload,
274-
ss.str(),
274+
errSs.str(),
275275
uploadSize,
276276
downloadSize);
277277
}
@@ -281,27 +281,27 @@ namespace ix
281281

282282
if (args->verbose)
283283
{
284-
std::stringstream ss;
285-
ss << "Sending " << verb << " request "
284+
std::stringstream verboseSs;
285+
verboseSs << "Sending " << verb << " request "
286286
<< "to " << host << ":" << port << std::endl
287287
<< "request size: " << req.size() << " bytes" << std::endl
288288
<< "=============" << std::endl
289289
<< req << "=============" << std::endl
290290
<< std::endl;
291291

292-
log(ss.str(), args);
292+
log(verboseSs.str(), args);
293293
}
294294

295295
if (!_socket->writeBytes(req, isCancellationRequested))
296296
{
297297
auto errorCode = args->cancel ? HttpErrorCode::Cancelled : HttpErrorCode::SendError;
298-
std::string errorMsg("Cannot send request");
298+
std::string msg("Cannot send request");
299299
return std::make_shared<HttpResponse>(code,
300300
description,
301301
errorCode,
302302
headers,
303303
payload,
304-
errorMsg,
304+
msg,
305305
uploadSize,
306306
downloadSize);
307307
}
@@ -315,33 +315,33 @@ namespace ix
315315
if (!lineValid)
316316
{
317317
auto errorCode = args->cancel ? HttpErrorCode::Cancelled : HttpErrorCode::CannotReadStatusLine;
318-
std::string errorMsg("Cannot retrieve status line");
318+
std::string msg("Cannot retrieve status line");
319319
return std::make_shared<HttpResponse>(code,
320320
description,
321321
errorCode,
322322
headers,
323323
payload,
324-
errorMsg,
324+
msg,
325325
uploadSize,
326326
downloadSize);
327327
}
328328

329329
if (args->verbose)
330330
{
331-
std::stringstream ss;
332-
ss << "Status line " << line;
333-
log(ss.str(), args);
331+
std::stringstream verboseSs;
332+
verboseSs << "Status line " << line;
333+
log(verboseSs.str(), args);
334334
}
335335

336336
if (sscanf(line.c_str(), "HTTP/1.1 %d", &code) != 1)
337337
{
338-
std::string errorMsg("Cannot parse response code from status line");
338+
std::string msg("Cannot parse response code from status line");
339339
return std::make_shared<HttpResponse>(code,
340340
description,
341341
HttpErrorCode::MissingStatus,
342342
headers,
343343
payload,
344-
errorMsg,
344+
msg,
345345
uploadSize,
346346
downloadSize);
347347
}
@@ -353,13 +353,13 @@ namespace ix
353353
if (!headersValid)
354354
{
355355
auto errorCode = args->cancel ? HttpErrorCode::Cancelled : HttpErrorCode::HeaderParsingError;
356-
std::string errorMsg("Cannot parse http headers");
356+
std::string msg("Cannot parse http headers");
357357
return std::make_shared<HttpResponse>(code,
358358
description,
359359
errorCode,
360360
headers,
361361
payload,
362-
errorMsg,
362+
msg,
363363
uploadSize,
364364
downloadSize);
365365
}
@@ -369,27 +369,27 @@ namespace ix
369369
{
370370
if (headers.find("Location") == headers.end())
371371
{
372-
std::string errorMsg("Missing location header for redirect");
372+
std::string msg("Missing location header for redirect");
373373
return std::make_shared<HttpResponse>(code,
374374
description,
375375
HttpErrorCode::MissingLocation,
376376
headers,
377377
payload,
378-
errorMsg,
378+
msg,
379379
uploadSize,
380380
downloadSize);
381381
}
382382

383383
if (redirects >= args->maxRedirects)
384384
{
385-
std::stringstream ss;
386-
ss << "Too many redirects: " << redirects;
385+
std::stringstream maxRedirectSs;
386+
maxRedirectSs << "Too many redirects: " << redirects;
387387
return std::make_shared<HttpResponse>(code,
388388
description,
389389
HttpErrorCode::TooManyRedirects,
390390
headers,
391391
payload,
392-
ss.str(),
392+
maxRedirectSs.str(),
393393
uploadSize,
394394
downloadSize);
395395
}
@@ -446,7 +446,7 @@ namespace ix
446446
else if (headers.find("Transfer-Encoding") != headers.end() &&
447447
headers["Transfer-Encoding"] == "chunked")
448448
{
449-
std::stringstream ss;
449+
std::stringstream chunkSizeSs;
450450

451451
while (true)
452452
{
@@ -467,9 +467,9 @@ namespace ix
467467
}
468468

469469
uint64_t chunkSize;
470-
ss.str("");
471-
ss << std::hex << line;
472-
ss >> chunkSize;
470+
chunkSizeSs.str("");
471+
chunkSizeSs << std::hex << line;
472+
chunkSizeSs >> chunkSize;
473473

474474
if (args->verbose)
475475
{
@@ -485,11 +485,11 @@ namespace ix
485485
isCancellationRequested);
486486
if (!chunkResult.first)
487487
{
488-
auto errorCode = args->cancel ? HttpErrorCode::Cancelled : HttpErrorCode::ChunkReadError;
488+
auto errCode = args->cancel ? HttpErrorCode::Cancelled : HttpErrorCode::ChunkReadError;
489489
errorMsg = "Cannot read chunk";
490490
return std::make_shared<HttpResponse>(code,
491491
description,
492-
errorCode,
492+
errCode,
493493
headers,
494494
payload,
495495
errorMsg,
@@ -508,10 +508,10 @@ namespace ix
508508

509509
if (!lineResult.first)
510510
{
511-
auto errorCode = args->cancel ? HttpErrorCode::Cancelled : HttpErrorCode::ChunkReadError;
511+
auto errCode = args->cancel ? HttpErrorCode::Cancelled : HttpErrorCode::ChunkReadError;
512512
return std::make_shared<HttpResponse>(code,
513513
description,
514-
errorCode,
514+
errCode,
515515
headers,
516516
payload,
517517
errorMsg,
@@ -528,13 +528,13 @@ namespace ix
528528
}
529529
else
530530
{
531-
std::string errorMsg("Cannot read http body");
531+
std::string msg("Cannot read http body");
532532
return std::make_shared<HttpResponse>(code,
533533
description,
534534
HttpErrorCode::CannotReadBody,
535535
headers,
536536
payload,
537-
errorMsg,
537+
msg,
538538
uploadSize,
539539
downloadSize);
540540
}
@@ -548,25 +548,25 @@ namespace ix
548548
std::string decompressedPayload;
549549
if (!gzipDecompress(payload, decompressedPayload))
550550
{
551-
std::string errorMsg("Error decompressing payload");
551+
std::string msg("Error decompressing payload");
552552
return std::make_shared<HttpResponse>(code,
553553
description,
554554
HttpErrorCode::Gzip,
555555
headers,
556556
payload,
557-
errorMsg,
557+
msg,
558558
uploadSize,
559559
downloadSize);
560560
}
561561
payload = decompressedPayload;
562562
#else
563-
std::string errorMsg("ixwebsocket was not compiled with gzip support on");
563+
std::string msg("ixwebsocket was not compiled with gzip support on");
564564
return std::make_shared<HttpResponse>(code,
565565
description,
566566
HttpErrorCode::Gzip,
567567
headers,
568568
payload,
569-
errorMsg,
569+
msg,
570570
uploadSize,
571571
downloadSize);
572572
#endif

ixwebsocket/IXHttpServer.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ namespace ix
9797
if (std::get<0>(ret))
9898
{
9999
auto request = std::get<2>(ret);
100-
std::shared_ptr<ix::HttpResponse> response;
101100
if (request->headers["Upgrade"] == "websocket")
102101
{
103102
WebSocketServer::handleUpgrade(std::move(socket), connectionState, request);

ixwebsocket/IXWebSocketHandshake.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ namespace ix
172172
// HTTP/1.0 is too old.
173173
if (httpVersion != "HTTP/1.1")
174174
{
175-
std::stringstream ss;
176-
ss << "Expecting HTTP/1.1, got " << httpVersion << ". "
175+
std::stringstream httpVersionSs;
176+
httpVersionSs << "Expecting HTTP/1.1, got " << httpVersion << ". "
177177
<< "Rejecting connection to " << url << ", status: " << status
178178
<< ", HTTP Status line: " << line;
179-
return WebSocketInitResult(false, status, ss.str());
179+
return WebSocketInitResult(false, status, httpVersionSs.str());
180180
}
181181

182182
auto result = parseHttpHeaders(_socket, isCancellationRequested);
@@ -192,11 +192,11 @@ namespace ix
192192
// a redirection (like 301)
193193
if (status != 101)
194194
{
195-
std::stringstream ss;
196-
ss << "Expecting status 101 (Switching Protocol), got " << status
195+
std::stringstream statusSs;
196+
statusSs << "Expecting status 101 (Switching Protocol), got " << status
197197
<< " status connecting to " << url << ", HTTP Status line: " << line;
198198

199-
return WebSocketInitResult(false, status, ss.str(), headers, path);
199+
return WebSocketInitResult(false, status, statusSs.str(), headers, path);
200200
}
201201

202202
// Check the presence of the connection field
@@ -214,9 +214,9 @@ namespace ix
214214
//
215215
if (!insensitiveStringCompare(headers["connection"], "Upgrade"))
216216
{
217-
std::stringstream ss;
218-
ss << "Invalid connection value: " << headers["connection"];
219-
return WebSocketInitResult(false, status, ss.str());
217+
std::stringstream connSs;
218+
connSs << "Invalid connection value: " << headers["connection"];
219+
return WebSocketInitResult(false, status, connSs.str());
220220
}
221221

222222
char output[29] = {};

ixwebsocket/IXWebSocketTransport.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ namespace ix
10621062
{
10631063
ssize_t ret = 0;
10641064
{
1065-
std::lock_guard<std::mutex> lock(_socketMutex);
1065+
std::lock_guard<std::mutex> socketLock(_socketMutex);
10661066
ret = _socket->send((char*) &_txbuf[0], _txbuf.size());
10671067
}
10681068

ws/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ project (ws)
88

99
# There's -Weverything too for clang
1010
if (NOT WIN32)
11-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
11+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -Wshadow -Wunused -pedantic")
1212
endif()
1313

1414
set (CMAKE_CXX_STANDARD 11)

0 commit comments

Comments
 (0)