Skip to content

Commit 0a8c11b

Browse files
authored
Fixes various MSVC compiler warnings. (#1547)
* Fixed MSVC C4129 * Fixed MSVC C6262. * Attempt to suppress MSVC C26444 in PTF_ASSERT_RAISES. * Fixed MSVC C26817 * Fixed MSVC C6387 * Fixed MSVC C26478 * Fixed C28182 * Fixed C6297 * Fixes C6011 * Fixed C26439.
1 parent fdd4caf commit 0a8c11b

File tree

13 files changed

+50
-21
lines changed

13 files changed

+50
-21
lines changed

Examples/DnsSpoofing/main.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* address as the resolved IP. Then it's sent back on the network on the same interface
77
*/
88

9+
#include <stdexcept>
910
#include <vector>
1011
#include <iostream>
1112
#include <algorithm>
@@ -205,11 +206,15 @@ void handleDnsRequest(pcpp::RawPacket* packet, pcpp::PcapLiveDevice* dev, void*
205206
ip4Layer->setDstIPv4Address(srcIP.getIPv4());
206207
ip4Layer->getIPv4Header()->ipId = 0;
207208
}
208-
else
209+
else if (ip6Layer != nullptr)
209210
{
210211
ip6Layer->setSrcIPv6Address(ip6Layer->getDstIPv6Address());
211212
ip6Layer->setDstIPv6Address(srcIP.getIPv6());
212213
}
214+
else
215+
{
216+
throw std::logic_error("IPLayer should be either IPv4Layer or IPv6Layer");
217+
}
213218

214219
// reverse src and dst UDP ports
215220
uint16_t srcPort = udpLayer->getUdpHeader()->portSrc;

Examples/IcmpFileTransfer/IcmpFileTransfer-pitcher.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include <stdlib.h>
10+
#include <stdexcept>
1011
#include <iostream>
1112
#include <fstream>
1213
#ifndef _MSC_VER
@@ -37,6 +38,10 @@ void usleep(__int64 usec)
3738
ft.QuadPart = -(10 * usec); // Convert to 100 nanosecond interval, negative value indicates relative time
3839

3940
timer = CreateWaitableTimer(NULL, TRUE, NULL);
41+
if (timer == nullptr)
42+
{
43+
throw std::runtime_error("Could not create waitable timer with error: " + std::to_string(GetLastError()));
44+
}
4045
SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0);
4146
WaitForSingleObject(timer, INFINITE);
4247
CloseHandle(timer);

Packet++/header/HttpLayer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -710,13 +710,13 @@ namespace pcpp
710710
class HttpRequestFirstLineException : public std::exception
711711
{
712712
public:
713-
~HttpRequestFirstLineException() throw()
713+
~HttpRequestFirstLineException() noexcept
714714
{}
715715
void setMessage(const std::string& message)
716716
{
717717
m_Message = message;
718718
}
719-
virtual const char* what() const throw()
719+
virtual const char* what() const noexcept
720720
{
721721
return m_Message.c_str();
722722
}
@@ -857,13 +857,13 @@ namespace pcpp
857857
class HttpResponseFirstLineException : public std::exception
858858
{
859859
public:
860-
~HttpResponseFirstLineException() throw()
860+
~HttpResponseFirstLineException() noexcept
861861
{}
862862
void setMessage(const std::string& message)
863863
{
864864
m_Message = message;
865865
}
866-
virtual const char* what() const throw()
866+
virtual const char* what() const noexcept
867867
{
868868
return m_Message.c_str();
869869
}

Packet++/header/SipLayer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,13 +614,13 @@ namespace pcpp
614614
class SipRequestFirstLineException : public std::exception
615615
{
616616
public:
617-
~SipRequestFirstLineException() throw()
617+
~SipRequestFirstLineException() noexcept
618618
{}
619619
void setMessage(const std::string& message)
620620
{
621621
m_Message = message;
622622
}
623-
virtual const char* what() const throw()
623+
virtual const char* what() const noexcept
624624
{
625625
return m_Message.c_str();
626626
}
@@ -748,13 +748,13 @@ namespace pcpp
748748
class SipResponseFirstLineException : public std::exception
749749
{
750750
public:
751-
~SipResponseFirstLineException() throw()
751+
~SipResponseFirstLineException() noexcept
752752
{}
753753
void setMessage(const std::string& message)
754754
{
755755
m_Message = message;
756756
}
757-
virtual const char* what() const throw()
757+
virtual const char* what() const noexcept
758758
{
759759
return m_Message.c_str();
760760
}

Packet++/src/FtpLayer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ namespace pcpp
1717
std::string field = getCommandString();
1818

1919
for (size_t idx = 0; idx < field.size(); ++idx)
20-
val |= (field.c_str()[idx] << (idx * 8));
20+
{
21+
val |= static_cast<size_t>(field.c_str()[idx]) << (idx * 8);
22+
}
2123

2224
return static_cast<FtpCommand>(val);
2325
}

Packet++/src/IPv6Layer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#define LOG_MODULE PacketLogModuleIPv6Layer
22

3+
#include <stdexcept>
34
#include "IPv6Layer.h"
45
#include "IPv4Layer.h"
56
#include "PayloadLayer.h"
@@ -133,6 +134,10 @@ namespace pcpp
133134
}
134135
else
135136
{
137+
if (curExt == nullptr)
138+
{
139+
throw std::logic_error("curExt is nullptr");
140+
}
136141
curExt->setNextHeader(newExt);
137142
curExt = curExt->getNextHeader();
138143
}

Packet++/src/SipLayer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ namespace pcpp
360360
SipRequestLayer::SipRequestLayer(SipMethod method, const std::string& requestUri, const std::string& version)
361361
{
362362
m_Protocol = SIPRequest;
363-
m_FirstLine = new SipRequestFirstLine(this, method, std::move(version), std::move(requestUri));
363+
m_FirstLine = new SipRequestFirstLine(this, method, version, requestUri);
364364
m_FieldsOffset = m_FirstLine->getSize();
365365
}
366366

@@ -598,7 +598,7 @@ namespace pcpp
598598
const std::string& sipVersion)
599599
{
600600
m_Protocol = SIPResponse;
601-
m_FirstLine = new SipResponseFirstLine(this, std::move(sipVersion), statusCode, std::move(statusCodeString));
601+
m_FirstLine = new SipResponseFirstLine(this, sipVersion, statusCode, std::move(statusCodeString));
602602
m_FieldsOffset = m_FirstLine->getSize();
603603
}
604604

Packet++/src/SmtpLayer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ namespace pcpp
1818
std::string field = getCommandString();
1919

2020
for (size_t idx = 0; idx < field.size(); ++idx)
21-
val |= (field.c_str()[idx] << (idx * 8));
21+
{
22+
val |= static_cast<size_t>(field.c_str()[idx]) << (idx * 8);
23+
}
2224

2325
return static_cast<SmtpCommand>(val);
2426
}

Packet++/src/TextBasedProtocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ namespace pcpp
529529
{
530530
m_NameValueSeparator = nameValueSeparator;
531531
m_SpacesAllowedBetweenNameAndValue = spacesAllowedBetweenNameAndValue;
532-
initNewField(std::move(name), std::move(value));
532+
initNewField(name, value);
533533
}
534534

535535
void HeaderField::initNewField(const std::string& name, const std::string& value)

Packet++/src/VrrpLayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ namespace pcpp
251251

252252
size_t ipAddrOffset = 0;
253253
uint8_t* newIpAddresses = getData() + offset;
254-
for (auto ipAddress : ipAddresses)
254+
for (auto const& ipAddress : ipAddresses)
255255
{
256256
copyIPAddressToData(newIpAddresses + ipAddrOffset, ipAddress);
257257
ipAddrOffset += ipAddrLen;

0 commit comments

Comments
 (0)