Skip to content

Commit f33247a

Browse files
authored
Fix variableScope (#985)
1 parent 0f63838 commit f33247a

File tree

8 files changed

+15
-17
lines changed

8 files changed

+15
-17
lines changed

Common++/src/IpUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ inet_pton6(const char* src, uint8_t* dst)
267267
static const char xdigits_l[] = "0123456789abcdef",
268268
xdigits_u[] = "0123456789ABCDEF";
269269
u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
270-
const char *xdigits, *curtok;
270+
const char *curtok;
271271
int ch, saw_xdigit;
272272
u_int val;
273273

@@ -283,7 +283,7 @@ inet_pton6(const char* src, uint8_t* dst)
283283
val = 0;
284284
while ((ch = *src++) != '\0')
285285
{
286-
const char* pch;
286+
const char* pch, *xdigits;
287287

288288
if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
289289
pch = strchr((xdigits = xdigits_u), ch);

Examples/KniPong/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ void pingPongProcess(const LinuxSocket& sock)
522522
size_t netbuffPos = 0;
523523
unsigned char ttybuff[IO_BUFF_SIZE];
524524
size_t ttybuffPos = 0;
525-
int n, num_fds;
525+
int n;
526526
ssize_t ret;
527527

528528
/* stdin */
@@ -554,7 +554,7 @@ void pingPongProcess(const LinuxSocket& sock)
554554
return;
555555

556556
/* poll */
557-
num_fds = poll(pfd, 4, DEFAULT_POLL_TIMEOUT);
557+
int num_fds = poll(pfd, 4, DEFAULT_POLL_TIMEOUT);
558558

559559
/* treat poll errors */
560560
if (num_fds == -1)

Packet++/src/HttpLayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ int HttpResponseFirstLine::getStatusCodeAsInt() const
793793
std::string HttpResponseFirstLine::getStatusCodeString() const
794794
{
795795
std::string result;
796-
int statusStringOffset = 13;
796+
const int statusStringOffset = 13;
797797
if (m_StatusCode != HttpResponseLayer::HttpStatusCodeUnknown)
798798
{
799799
int statusStringEndOffset = m_FirstLineEndOffset - 2;

Packet++/src/Packet.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,9 +691,10 @@ std::string Packet::printPacketInfo(bool timeAsLocalTime) const
691691
nowtm = gmtime(&nowtime);
692692
#endif
693693

694-
char tmbuf[64], buf[128];
694+
char buf[128];
695695
if (nowtm != NULL)
696696
{
697+
char tmbuf[64];
697698
strftime(tmbuf, sizeof(tmbuf), "%Y-%m-%d %H:%M:%S", nowtm);
698699
snprintf(buf, sizeof(buf), "%s.%09lu", tmbuf, (unsigned long)timestamp.tv_nsec);
699700
}

Packet++/src/SipLayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ int SipResponseFirstLine::getStatusCodeAsInt() const
753753
std::string SipResponseFirstLine::getStatusCodeString() const
754754
{
755755
std::string result;
756-
int statusStringOffset = 12;
756+
const int statusStringOffset = 12;
757757
if (m_StatusCode != SipResponseLayer::SipStatusCodeUnknown)
758758
{
759759
int statusStringEndOffset = m_FirstLineEndOffset - 2;

Packet++/src/TelnetLayer.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,10 @@ size_t TelnetLayer::getTotalNumberOfCommands()
147147
if (isCommandField(m_Data))
148148
++ctr;
149149

150-
size_t offset = 0;
151150
uint8_t *pos = m_Data;
152151
while (pos != NULL)
153152
{
154-
offset = pos - m_Data;
153+
size_t offset = pos - m_Data;
155154
pos = getNextCommandField(pos, m_DataLen - offset);
156155
if (pos)
157156
++ctr;
@@ -169,11 +168,10 @@ size_t TelnetLayer::getNumberOfCommands(TelnetCommand command)
169168
if (isCommandField(m_Data) && m_Data[1] == command)
170169
++ctr;
171170

172-
size_t offset = 0;
173171
uint8_t *pos = m_Data;
174172
while (pos != NULL)
175173
{
176-
offset = pos - m_Data;
174+
size_t offset = pos - m_Data;
177175
pos = getNextCommandField(pos, m_DataLen - offset);
178176
if (pos && pos[1] == command)
179177
++ctr;
@@ -235,10 +233,9 @@ TelnetLayer::TelnetOption TelnetLayer::getOption(TelnetCommand command)
235233
return static_cast<TelnetOption>(getSubCommand(m_Data, getFieldLen(m_Data, m_DataLen)));
236234

237235
uint8_t *pos = m_Data;
238-
size_t offset = 0;
239236
while (pos != NULL)
240237
{
241-
offset = pos - m_Data;
238+
size_t offset = pos - m_Data;
242239
pos = getNextCommandField(pos, m_DataLen - offset);
243240

244241
if (pos && pos[1] == command)
@@ -282,10 +279,9 @@ uint8_t *TelnetLayer::getOptionData(TelnetCommand command, size_t &length)
282279
}
283280

284281
uint8_t *pos = m_Data;
285-
size_t offset = 0;
286282
while (pos != NULL)
287283
{
288-
offset = pos - m_Data;
284+
size_t offset = pos - m_Data;
289285
pos = getNextCommandField(pos, m_DataLen - offset);
290286

291287
if (pos && pos[1] == command)

Pcap++/src/PcapLiveDevice.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ int PcapLiveDevice::startCaptureBlockingMode(OnPacketArrivesStopBlocking onPacke
474474
long startTimeSec = 0, startTimeNSec = 0;
475475
clockGetTime(startTimeSec, startTimeNSec);
476476

477-
long curTimeSec = 0, curTimeNSec = 0;
477+
long curTimeSec = 0;
478478

479479
m_CaptureThreadStarted = true;
480480
m_StopThread = false;
@@ -491,6 +491,7 @@ int PcapLiveDevice::startCaptureBlockingMode(OnPacketArrivesStopBlocking onPacke
491491
{
492492
while (!m_StopThread && curTimeSec <= (startTimeSec + timeout))
493493
{
494+
long curTimeNSec = 0;
494495
pcap_dispatch(m_PcapDescriptor, -1, onPacketArrivesBlockingMode, (uint8_t*)this);
495496
clockGetTime(curTimeSec, curTimeNSec);
496497
}

Tests/Pcap++Test/Tests/KniTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ PTF_TEST_CASE(TestKniDevice)
116116

117117
// Assume that DPDK was initialized correctly in DpdkDevice tests
118118
uint16_t KNI_TEST_MTU = 1540;
119-
uint16_t KNI_NEW_MTU = 1500;
120119
bool isLinkUp = true;
121120
pcpp::KniDevice* device = NULL;
122121
pcpp::KniDevice::KniDeviceConfiguration devConfig;
@@ -202,6 +201,7 @@ PTF_TEST_CASE(TestKniDevice)
202201
}
203202
if (pcpp::KniDeviceList::isCallbackSupported(pcpp::KniDeviceList::CALLBACK_MTU))
204203
{
204+
uint16_t KNI_NEW_MTU = 1500;
205205
bool mtuSet = device->setMtu(KNI_NEW_MTU);
206206
PTF_NON_CRITICAL_TRUE(mtuSet);
207207
if (mtuSet)

0 commit comments

Comments
 (0)