Solve some compiler warnings:

usage of memory after free (false positive)
unused variable (stacked mutex)
malloc parameter type mismatch
This commit is contained in:
Gio 2016-08-26 13:10:09 +02:00
parent 746f4d7292
commit 5274b8aa97

View File

@ -243,12 +243,13 @@ void UdpLayer::run()
/* higher level interface */ /* higher level interface */
void UdpLayer::recv_loop() void UdpLayer::recv_loop()
{ {
int maxsize = 16000; size_t maxsize = 16000;
void *inbuf = malloc(maxsize); void *inbuf = malloc(maxsize);
if(inbuf == NULL) if(inbuf == NULL)
{ {
std::cerr << "(EE) Error in memory allocation of size " << maxsize << " in " << __PRETTY_FUNCTION__ << std::endl; std::cerr << "(EE) Error in memory allocation of size " << maxsize
<< " in " << __PRETTY_FUNCTION__ << std::endl;
return; return;
} }
@ -257,13 +258,12 @@ void UdpLayer::recv_loop()
while(1) while(1)
{ {
fd_set rset;
for(;;) for(;;)
{ {
/* check if we need to stop */ /* check if we need to stop */
bool toStop = false; bool toStop = false;
{ {
bdStackMutex stack(sockMtx); /********** LOCK MUTEX *********/ bdStackMutex stack(sockMtx); (void) stack;
toStop = stopThread; toStop = stopThread;
} }
@ -274,45 +274,37 @@ void UdpLayer::recv_loop()
#endif #endif
free(inbuf); free(inbuf);
stop(); stop();
return; // Avoid compiler warning about usage of inbuf after free
} }
fd_set rset;
FD_ZERO(&rset); FD_ZERO(&rset);
FD_SET(sockfd, &rset); FD_SET(sockfd, &rset);
timeout.tv_sec = 0; timeout.tv_sec = 0;
timeout.tv_usec = 500000; /* 500 ms timeout */ timeout.tv_usec = 500000; // 500 ms timeout
status = select(sockfd+1, &rset, NULL, NULL, &timeout); status = select(sockfd+1, &rset, NULL, NULL, &timeout);
if (status > 0) if (status > 0) break; // data available, go read it
{
break; /* data available, go read it */
}
else if (status < 0)
{
#ifdef DEBUG_UDP_LAYER #ifdef DEBUG_UDP_LAYER
std::cerr << "UdpLayer::recv_loop() Error: " << bdnet_errno() << std::endl; else if (status < 0) std::cerr << "UdpLayer::recv_loop() Error: "
<< bdnet_errno() << std::endl;
#endif #endif
}
}; };
int nsize = maxsize; int nsize = static_cast<int>(maxsize);
struct sockaddr_in from; struct sockaddr_in from;
if (0 < receiveUdpPacket(inbuf, &nsize, from)) if (0 < receiveUdpPacket(inbuf, &nsize, from))
{ {
#ifdef DEBUG_UDP_LAYER #ifdef DEBUG_UDP_LAYER
std::cerr << "UdpLayer::readPkt() from : " << from << std::endl; std::cerr << "UdpLayer::readPkt() from : " << from << std::endl
std::cerr << printPkt(inbuf, nsize); << printPkt(inbuf, nsize);
#endif #endif
// send to reciever. recv->recvPkt(inbuf, nsize, from); // pass to reciever.
recv -> recvPkt(inbuf, nsize, from);
} }
else
{
#ifdef DEBUG_UDP_LAYER #ifdef DEBUG_UDP_LAYER
std::cerr << "UdpLayer::readPkt() not ready" << from; else std::cerr << "UdpLayer::readPkt() not ready" << from << std::endl;
std::cerr << std::endl;
#endif #endif
} }
} }
}
int UdpLayer::sendPkt(const void *data, int size, const sockaddr_in &to, int ttl) int UdpLayer::sendPkt(const void *data, int size, const sockaddr_in &to, int ttl)