Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usages of variable length arrays #758

Merged
merged 1 commit into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Fw/FilePacket/PathName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace Fw {

{
const U8* addrLeft = serialBuffer.getBuffAddrLeft();
U8 bytes[this->length];
U8 bytes[MAX_LENGTH];
const SerializeStatus status =
serialBuffer.popBytes(bytes, this->length);
if (status != FW_SERIALIZE_OK)
Expand Down
5 changes: 3 additions & 2 deletions Svc/BufferLogger/BufferLoggerFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,16 @@ namespace Svc {
bool BufferLogger::File ::
writeSize(const U32 size)
{
FW_ASSERT(this->sizeOfSize <= sizeof(U32));
U8 sizeBuffer[sizeof(U32)];
U32 sizeRegister = size;
U8 sizeBuffer[this->sizeOfSize];
for (U8 i = 0; i < this->sizeOfSize; ++i) {
sizeBuffer[this->sizeOfSize - i - 1] = sizeRegister & 0xFF;
sizeRegister >>= 8;
}
const bool status = this->writeBytes(
sizeBuffer,
sizeof(sizeBuffer)
this->sizeOfSize
);
return status;
}
Expand Down
2 changes: 1 addition & 1 deletion Svc/FileDownlink/FileDownlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ namespace Svc {
FW_ASSERT(byteOffset < this->endOffset);
const U32 maxDataSize = FILEDOWNLINK_INTERNAL_BUFFER_SIZE - Fw::FilePacket::DataPacket::HEADERSIZE;
const U32 dataSize = (byteOffset + maxDataSize > this->endOffset) ? (this->endOffset - byteOffset) : maxDataSize;
U8 buffer[dataSize];
U8 buffer[FILEDOWNLINK_INTERNAL_BUFFER_SIZE - Fw::FilePacket::DataPacket::HEADERSIZE];
//This will be last data packet sent
if (dataSize + byteOffset == this->endOffset) {
this->lastCompletedType = Fw::FilePacket::T_DATA;
Expand Down
11 changes: 6 additions & 5 deletions Svc/FileUplink/File.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ======================================================================
// ======================================================================
// \title File.cpp
// \author bocchino
// \brief cpp file for FileUplink::File
Expand All @@ -7,24 +7,25 @@
// Copyright 2009-2016, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
//
// ======================================================================

#include <Svc/FileUplink/FileUplink.hpp>
#include <Fw/Types/Assert.hpp>
#include <Fw/Types/StringUtils.hpp>

namespace Svc {

Os::File::Status FileUplink::File ::
open(const Fw::FilePacket::StartPacket& startPacket)
{
const U32 length = startPacket.destinationPath.length;
char path[length + 1];
char path[Fw::FilePacket::PathName::MAX_LENGTH + 1];
memcpy(path, startPacket.destinationPath.value, length);
path[length] = 0;
this->size = startPacket.fileSize;
Fw::LogStringArg logStringArg(path);
this->name = logStringArg;
this->size = startPacket.fileSize;
CFDP::Checksum checksum;
this->checksum = checksum;
return this->osFile.open(path, Os::File::OPEN_WRITE);
Expand Down
10 changes: 5 additions & 5 deletions Svc/GroundInterface/GroundInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ======================================================================
// ======================================================================
// \title GroundInterface.cpp
// \author lestarch
// \brief cpp file for GroundInterface component implementation class
// ======================================================================
// ======================================================================

#include <Fw/Com/ComPacket.hpp>
#include <Svc/GroundInterface/GroundInterface.hpp>
Expand All @@ -16,7 +16,7 @@ namespace Svc {
const U32 GroundInterfaceComponentImpl::END_WORD = static_cast<U32>(0xcafecafe);

// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// Construction, initialization, and destruction
// ----------------------------------------------------------------------

GroundInterfaceComponentImpl ::
Expand All @@ -33,7 +33,7 @@ namespace Svc {
void GroundInterfaceComponentImpl ::
init(
const NATIVE_INT_TYPE instance
)
)
{
GroundInterfaceComponentBase::init(instance);
}
Expand Down Expand Up @@ -129,7 +129,7 @@ namespace Svc {

//read packet descriptor in size agnostic way
U8 packet_descriptor_size = sizeof(FwPacketDescriptorType);
U8 packet_type_bytes[packet_descriptor_size];
U8 packet_type_bytes[sizeof(FwPacketDescriptorType)];
Fw::SerializeStatus stat = m_in_ring.peek(packet_type_bytes, packet_descriptor_size, HEADER_SIZE);
//m_in_ring.peek(packet_type, HEADER_SIZE); // this way is only valid for 4byte packet descriptors
if(stat == Fw::FW_SERIALIZE_OK)
Expand Down