Skip to content

Commit

Permalink
all: Fixed 'warning: variable length arrays in C++ are a Clang extens…
Browse files Browse the repository at this point in the history
…ion'.
  • Loading branch information
levy committed Oct 14, 2024
1 parent ce08305 commit ccdc34a
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/inet/applications/netperfmeter/NetPerfMeter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ void NetPerfMeter::sendDataOfSaturatedStreams(const unsigned long long bytesAvai
if (SendingAllowed) {
// ====== SCTP tells current queue occupation for each stream =========
unsigned long long contingent;
unsigned long long queued[ActualOutboundStreams];
unsigned long long *queued = new unsigned long long[ActualOutboundStreams];
if (sendQueueAbatedIndication == nullptr) {
// At the moment, the actual queue size is unknown.
// => Assume it to be bytesAvailableInQueue.
Expand Down Expand Up @@ -1075,6 +1075,7 @@ void NetPerfMeter::sendDataOfSaturatedStreams(const unsigned long long bytesAvai
LastStreamID = (LastStreamID + 1) % ActualOutboundStreams;
} while (LastStreamID != startStreamID);
} while ((newlyQueuedBytes < bytesAvailableInQueue) && (progress == true));
delete [] queued;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/inet/applications/sctpapp/SctpNatPeer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ void SctpNatPeer::handleMessage(cMessage *msg)
if (rendezvous) {
const auto& smsg = message->peekDataAsBytes();
int bufferlen = B(smsg->getChunkLength()).get();
uint8_t buffer[bufferlen];
uint8_t *buffer = new uint8_t[bufferlen];
std::vector<uint8_t> vec = smsg->getBytes();
for (int i = 0; i < bufferlen; i++) {
buffer[i] = vec[i];
Expand All @@ -372,6 +372,7 @@ void SctpNatPeer::handleMessage(cMessage *msg)
}
peerPort = nat->portPeer2;
delete msg;
delete [] buffer;
}
else {
auto j = rcvdBytesPerAssoc.find(id);
Expand Down
3 changes: 2 additions & 1 deletion src/inet/applications/sctpapp/SctpNatServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void SctpNatServer::handleMessage(cMessage *msg)
id = ind->getSocketId();
const auto& smsg = message->peekDataAsBytes();
int bufferlen = B(smsg->getChunkLength()).get();
uint8_t buffer[bufferlen];
uint8_t *buffer = new uint8_t[bufferlen];
std::vector<uint8_t> vec = smsg->getBytes();
for (int i = 0; i < bufferlen; i++) {
buffer[i] = vec[i];
Expand Down Expand Up @@ -358,6 +358,7 @@ void SctpNatServer::handleMessage(cMessage *msg)
printNatVector();

delete msg;
delete [] buffer;
break;
}

Expand Down
3 changes: 2 additions & 1 deletion src/inet/applications/voipstream/VoipStreamReceiver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ void VoipStreamReceiver::Connection::writeLostSamples(int sampleCount)
{
int pktBytes = sampleCount * av_get_bytes_per_sample(decCtx->sample_fmt);
if (outFile.isOpen()) {
uint8_t decBuf[pktBytes];
uint8_t *decBuf = new uint8_t[pktBytes];
memset(decBuf, 0, pktBytes);
outFile.write(decBuf, pktBytes);
delete [] decBuf;
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/inet/emulation/linklayer/ethernet/ExtEthernetSocket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ void ExtEthernetSocket::handleMessage(cMessage *message)
socket_address.sll_addr[4] = macAddress.getAddressByte(4);
socket_address.sll_addr[5] = macAddress.getAddressByte(5);

uint8_t buffer[packet->getByteLength()];
size_t bufferSize = packet->getByteLength();
uint8_t *buffer = new uint8_t[bufferSize];
auto bytesChunk = packet->peekAllAsBytes();
size_t packetLength = bytesChunk->copyToBuffer(buffer, sizeof(buffer));
size_t packetLength = bytesChunk->copyToBuffer(buffer, bufferSize);
ASSERT(packetLength == (size_t)packet->getByteLength());

int sent = sendto(fd, buffer, packetLength, 0, (struct sockaddr *)&socket_address, sizeof(socket_address));
Expand All @@ -81,6 +82,7 @@ void ExtEthernetSocket::handleMessage(cMessage *message)

numSent++;
delete packet;
delete [] buffer;
}

void ExtEthernetSocket::refreshDisplay() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void ExtEthernetTapDevice::handleMessage(cMessage *msg)
const auto& ethHeader = packet->peekAtFront<EthernetMacHeader>();
packet->popAtBack<EthernetFcs>(ETHER_FCS_BYTES);
auto bytesChunk = packet->peekDataAsBytes();
uint8_t buffer[packet->getByteLength() + 4];
uint8_t *buffer = new uint8_t[packet->getByteLength() + 4];
buffer[0] = 0;
buffer[1] = 0;
buffer[2] = 0x86; // Ethernet
Expand All @@ -78,6 +78,7 @@ void ExtEthernetTapDevice::handleMessage(cMessage *msg)
else
EV_ERROR << "Sending Ethernet packet FAILED! (sendto returned " << nwrite << " (" << strerror(errno) << ") instead of " << packetLength << ").\n";
delete packet;
delete [] buffer;
}

void ExtEthernetTapDevice::refreshDisplay() const
Expand Down
3 changes: 2 additions & 1 deletion src/inet/emulation/networklayer/ipv4/ExtIpv4TunDevice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void ExtIpv4TunDevice::handleMessage(cMessage *msg)
throw cRuntimeError("Accepts IPv4 packets only");
const auto& ipv4Header = packet->peekAtFront<Ipv4Header>();
auto bytesChunk = packet->peekDataAsBytes();
uint8_t buffer[packet->getByteLength()];
uint8_t *buffer = new uint8_t[packet->getByteLength()];
size_t packetLength = bytesChunk->copyToBuffer(buffer, packet->getByteLength());
ASSERT(packetLength == (size_t)packet->getByteLength());
ssize_t nwrite = write(fd, buffer, packetLength);
Expand All @@ -74,6 +74,7 @@ void ExtIpv4TunDevice::handleMessage(cMessage *msg)
else
EV_ERROR << "Sending IPv4 packet FAILED! (sendto returned " << nwrite << " (" << strerror(errno) << ") instead of " << packetLength << ").\n";
delete packet;
delete [] buffer;
}

void ExtIpv4TunDevice::refreshDisplay() const
Expand Down
3 changes: 2 additions & 1 deletion src/inet/emulation/transportlayer/udp/ExtLowerUdp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void ExtLowerUdp::processPacketFromUpper(Packet *packet)
else {
auto socket = it->second;
auto bytesChunk = packet->peekAllAsBytes();
uint8_t buffer[packet->getByteLength()];
uint8_t *buffer = new uint8_t[packet->getByteLength()];
size_t packetLength = bytesChunk->copyToBuffer(buffer, packet->getByteLength());
ASSERT(packetLength == (size_t)packet->getByteLength());
if (auto addressReq = packet->findTag<L3AddressReq>()) {
Expand All @@ -279,6 +279,7 @@ void ExtLowerUdp::processPacketFromUpper(Packet *packet)
throw cRuntimeError("Calling send failed: %d", n);
}
emit(packetSentSignal, packet);
delete [] buffer;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/inet/networklayer/ipv4/Ipv4HeaderSerializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const Ptr<Chunk> Ipv4HeaderSerializer::deserialize(MemoryInputStream& stream) co
{
auto position = stream.getPosition();
B bufsize = stream.getRemainingLength();
uint8_t buffer[B(IPv4_MIN_HEADER_LENGTH).get()];
uint8_t *buffer = new uint8_t[B(IPv4_MIN_HEADER_LENGTH).get()];
stream.readBytes(buffer, IPv4_MIN_HEADER_LENGTH);
auto ipv4Header = makeShared<Ipv4Header>();
const struct ip& iphdr = *static_cast<const struct ip *>((void *)&buffer);
Expand Down Expand Up @@ -198,7 +198,7 @@ const Ptr<Chunk> Ipv4HeaderSerializer::deserialize(MemoryInputStream& stream) co

ipv4Header->setCrc(ntohs(iphdr.ip_sum));
ipv4Header->setCrcMode(CRC_COMPUTED);

delete [] buffer;
return ipv4Header;
}

Expand Down
10 changes: 6 additions & 4 deletions src/inet/transportlayer/sctp/SctpAssociationUtil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,8 @@ inline static bool writeCompressedValue(uint8_t *outputBuffer,

static uint32_t compressGaps(const SctpGapList *gapList, const SctpGapList::GapType type, size_t& space)
{
uint8_t compressedDataBuffer[1 + 6 * gapList->getNumGaps(type)]; // Worst-case size
size_t compressedDataBufferSize = 1 + 6 * gapList->getNumGaps(type);
uint8_t *compressedDataBuffer = new uint8_t[compressedDataBufferSize]; // Worst-case size

size_t outputPos = 0;
unsigned int entriesWritten = 0;
Expand All @@ -1448,8 +1449,8 @@ static uint32_t compressGaps(const SctpGapList *gapList, const SctpGapList::GapT
const uint16_t startOffset = gapList->getGapStart(type, i) - last;
const uint16_t stopOffset = gapList->getGapStop(type, i) - gapList->getGapStart(type, i);
const size_t lastOutputPos = outputPos;
if ((writeCompressedValue((uint8_t *)&compressedDataBuffer, sizeof(compressedDataBuffer), outputPos, startOffset) == false) ||
(writeCompressedValue((uint8_t *)&compressedDataBuffer, sizeof(compressedDataBuffer), outputPos, stopOffset) == false) ||
if ((writeCompressedValue((uint8_t *)&compressedDataBuffer, compressedDataBufferSize, outputPos, startOffset) == false) ||
(writeCompressedValue((uint8_t *)&compressedDataBuffer, compressedDataBufferSize, outputPos, stopOffset) == false) ||
(outputPos + 1 > space))
{
outputPos = lastOutputPos;
Expand All @@ -1458,9 +1459,10 @@ static uint32_t compressGaps(const SctpGapList *gapList, const SctpGapList::GapT
entriesWritten++;
last = gapList->getGapStop(type, i);
}
ASSERT(writeCompressedValue((uint8_t *)&compressedDataBuffer, sizeof(compressedDataBuffer), outputPos, 0x00) == true);
ASSERT(writeCompressedValue((uint8_t *)&compressedDataBuffer, compressedDataBufferSize, outputPos, 0x00) == true);
space = outputPos;

delete [] compressedDataBuffer;
return entriesWritten;
}

Expand Down
4 changes: 3 additions & 1 deletion src/inet/transportlayer/sctp/SctpHeaderSerializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ const Ptr<Chunk> SctpHeaderSerializer::deserialize(MemoryInputStream& stream) co

// auto position = stream.getPosition();
int bufsize = B(stream.getRemainingLength()).get();
uint8_t buffer[bufsize];
uint8_t *buffer = new uint8_t[bufsize];
stream.readBytes(buffer, B(bufsize));
auto dest = makeShared<SctpHeader>();

Expand Down Expand Up @@ -1156,6 +1156,7 @@ const Ptr<Chunk> SctpHeaderSerializer::deserialize(MemoryInputStream& stream) co
int32_t chunkType = chunk->type;
woPadding = ntohs(chunk->length);
if (woPadding == 0) {
delete [] buffer;
return dest;
}
cLen = ADD_PADDING(woPadding);
Expand Down Expand Up @@ -2147,6 +2148,7 @@ const Ptr<Chunk> SctpHeaderSerializer::deserialize(MemoryInputStream& stream) co
chunkPtr += cLen;
} // end of while()
EV_INFO << "SctpSerializer - pkt info - " << B(dest->getChunkLength()).get() << " bytes" << endl;
delete [] buffer;
return dest;
}

Expand Down
3 changes: 2 additions & 1 deletion src/inet/transportlayer/tcp_common/TcpHeaderSerializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void TcpHeaderSerializer::serializeOption(MemoryOutputStream& stream, const TcpO
const Ptr<Chunk> TcpHeaderSerializer::deserialize(MemoryInputStream& stream) const
{
auto position = stream.getPosition();
uint8_t buffer[B(TCP_MIN_HEADER_LENGTH).get()];
uint8_t *buffer = new uint8_t[B(TCP_MIN_HEADER_LENGTH).get()];
stream.readBytes(buffer, TCP_MIN_HEADER_LENGTH);
auto tcpHeader = makeShared<TcpHeader>();
const struct tcphdr& tcp = *static_cast<const struct tcphdr *>((void *)&buffer);
Expand Down Expand Up @@ -194,6 +194,7 @@ const Ptr<Chunk> TcpHeaderSerializer::deserialize(MemoryInputStream& stream) con
tcpHeader->setHeaderLength(headerLength);
tcpHeader->setCrc(ntohs(tcp.th_sum));
tcpHeader->setCrcMode(CRC_COMPUTED);
delete [] buffer;
return tcpHeader;
}

Expand Down

0 comments on commit ccdc34a

Please sign in to comment.