Skip to content

Commit

Permalink
Fixing review comments - pt 1
Browse files Browse the repository at this point in the history
  • Loading branch information
LeStarch committed Feb 27, 2025
1 parent 1928a00 commit d636bbf
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Os/ValidateFileCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace Os {
if( File::OP_OK != status ) {
return status;
}
if( size != static_cast<FwSignedSizeType>(hashBuffer.getBuffCapacity()) ) {
if(static_cast<FwSizeType>(size) != hashBuffer.getBuffCapacity()) {
return File::BAD_SIZE;
}
hashFile.close();
Expand All @@ -105,7 +105,7 @@ namespace Os {
if( File::OP_OK != status ) {
return status;
}
if( size != static_cast<FwSignedSizeType>(hashBuffer.getBuffLength()) ) {
if(static_cast<FwSizeType>(size) != hashBuffer.getBuffLength()) {
return File::BAD_SIZE;
}
hashFile.close();
Expand Down
2 changes: 1 addition & 1 deletion Svc/ActiveTextLogger/LogFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace Svc {
FW_ASSERT(stat != Os::File::NOT_OPENED);

// Only return a good status if the write was valid
status = (static_cast<FwSizeType>(writeSize) == size);
status = (stat == Os::File::OP_OK) && (static_cast<FwSizeType>(writeSize) == size);

this->m_currentFileSize += static_cast<FwSizeType>(writeSize);
}
Expand Down
10 changes: 7 additions & 3 deletions Svc/BufferAccumulator/BufferAccumulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <sys/time.h>

#include "Fw/Types/BasicTypes.hpp"

#include <limits>

namespace Svc {

Expand Down Expand Up @@ -46,15 +46,19 @@ BufferAccumulator ::~BufferAccumulator() {}
// ----------------------------------------------------------------------

void BufferAccumulator ::allocateQueue(
NATIVE_INT_TYPE identifier, Fw::MemAllocator& allocator,
FwEnumStoreType identifier, Fw::MemAllocator& allocator,
NATIVE_UINT_TYPE maxNumBuffers //!< The maximum number of buffers
) {

this->m_allocatorId = identifier;
// Overflow protection
FW_ASSERT(
(std::numeric_limits<FwSizeType>::max() / maxNumBuffers) >= sizeof(Fw::Buffer)
);
FwSizeType memSize = static_cast<FwSizeType>(sizeof(Fw::Buffer) * maxNumBuffers);
bool recoverable = false;
this->m_bufferMemory = static_cast<Fw::Buffer*>(
allocator.allocate(static_cast<FwEnumStoreType>(identifier), memSize, recoverable));
allocator.allocate(identifier, memSize, recoverable));
//TODO: Fail gracefully here
m_bufferQueue.init(this->m_bufferMemory, maxNumBuffers);
}
Expand Down
4 changes: 2 additions & 2 deletions Svc/BufferAccumulator/BufferAccumulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace Svc {
//! Give the class a memory buffer. Should be called after constructor
//! and init, but before task is spawned.
void allocateQueue(
NATIVE_INT_TYPE identifier, Fw::MemAllocator& allocator,
FwEnumStoreType identifier, Fw::MemAllocator& allocator,
NATIVE_UINT_TYPE maxNumBuffers //!< The maximum number of buffers
);

Expand Down Expand Up @@ -204,7 +204,7 @@ namespace Svc {
U32 m_cmdSeq;

//! The allocator ID
NATIVE_INT_TYPE m_allocatorId;
FwEnumStoreType m_allocatorId;
};

} // namespace Svc
Expand Down
16 changes: 3 additions & 13 deletions Utils/CRCChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ static_assert(FW_USE_PRINTF_FAMILY_FUNCTIONS_IN_STRING_FORMATTING,
Os::File::Status stat;
Utils::Hash hash;
U32 checksum;
FwSignedSizeType int_file_size;
FwSignedSizeType bytes_to_read;
FwSignedSizeType bytes_to_write;
Fw::FileNameString hashFilename;
Expand All @@ -46,8 +45,6 @@ static_assert(FW_USE_PRINTF_FAMILY_FUNCTIONS_IN_STRING_FORMATTING,
return FAILED_FILE_SIZE;
}

int_file_size = filesize;

// Open file
stat = f.open(fname, Os::File::OPEN_READ);
if(stat != Os::File::OP_OK)
Expand All @@ -57,7 +54,7 @@ static_assert(FW_USE_PRINTF_FAMILY_FUNCTIONS_IN_STRING_FORMATTING,

// Read file
bytes_to_read = CRC_FILE_READ_BLOCK;
blocks = int_file_size / CRC_FILE_READ_BLOCK;
blocks = filesize / CRC_FILE_READ_BLOCK;
for(i = 0; i < blocks; i++)
{
stat = f.read(block_data, bytes_to_read);
Expand All @@ -70,7 +67,7 @@ static_assert(FW_USE_PRINTF_FAMILY_FUNCTIONS_IN_STRING_FORMATTING,
hash.update(block_data, static_cast<FwSizeType>(bytes_to_read));
}

remaining_bytes = int_file_size % CRC_FILE_READ_BLOCK;
remaining_bytes = filesize % CRC_FILE_READ_BLOCK;
bytes_to_read = remaining_bytes;
if(remaining_bytes > 0)
{
Expand Down Expand Up @@ -158,7 +155,6 @@ static_assert(FW_USE_PRINTF_FAMILY_FUNCTIONS_IN_STRING_FORMATTING,
Utils::Hash hash;
U32 checksum;
U32 checksum_from_file;
FwSignedSizeType int_file_size;
FwSignedSizeType bytes_to_read;
U8 block_data[CRC_FILE_READ_BLOCK];

Expand All @@ -168,12 +164,6 @@ static_assert(FW_USE_PRINTF_FAMILY_FUNCTIONS_IN_STRING_FORMATTING,
return FAILED_FILE_SIZE;
}

int_file_size = static_cast<FwSignedSizeType>(filesize);
if(static_cast<FwSignedSizeType>(int_file_size) != filesize)
{
return FAILED_FILE_SIZE_CAST;
}

// Open file
stat = f.open(fname, Os::File::OPEN_READ);
if(stat != Os::File::OP_OK)
Expand All @@ -196,7 +186,7 @@ static_assert(FW_USE_PRINTF_FAMILY_FUNCTIONS_IN_STRING_FORMATTING,
hash.update(block_data, static_cast<FwSizeType>(bytes_to_read));
}

remaining_bytes = int_file_size % CRC_FILE_READ_BLOCK;
remaining_bytes = filesize % CRC_FILE_READ_BLOCK;
bytes_to_read = remaining_bytes;
if(remaining_bytes > 0)
{
Expand Down
12 changes: 6 additions & 6 deletions Utils/Types/Queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void Queue::setup(U8* const storage, const FwSizeType storage_size, const FwSize
static_cast<FwAssertArgType>(storage_size),
static_cast<FwAssertArgType>(depth),
static_cast<FwAssertArgType>(message_size));
m_internal.setup(storage, static_cast<FwSizeType>(total_needed_size));
m_internal.setup(storage, total_needed_size);
m_message_size = message_size;
}

Expand All @@ -32,7 +32,7 @@ Fw::SerializeStatus Queue::enqueue(const U8* const message, const FwSizeType siz
m_message_size == size,
static_cast<FwAssertArgType>(size),
static_cast<FwAssertArgType>(m_message_size)); // Message size is as expected
return m_internal.serialize(message, static_cast<FwSizeType>(m_message_size));
return m_internal.serialize(message, m_message_size);
}

Fw::SerializeStatus Queue::dequeue(U8* const message, const FwSizeType size) {
Expand All @@ -41,16 +41,16 @@ Fw::SerializeStatus Queue::dequeue(U8* const message, const FwSizeType size) {
m_message_size <= size,
static_cast<FwAssertArgType>(size),
static_cast<FwAssertArgType>(m_message_size)); // Sufficient storage space for read message
Fw::SerializeStatus result = m_internal.peek(message, static_cast<FwSizeType>(m_message_size), 0);
Fw::SerializeStatus result = m_internal.peek(message, m_message_size, 0);
if (result != Fw::FW_SERIALIZE_OK) {
return result;
}
return m_internal.rotate(static_cast<FwSizeType>(m_message_size));
return m_internal.rotate(m_message_size);
}

FwSizeType Queue::get_high_water_mark() const {
FW_ASSERT(m_message_size > 0, static_cast<FwAssertArgType>(m_message_size));
return static_cast<FwSizeType>(m_internal.get_high_water_mark() / m_message_size);
return m_internal.get_high_water_mark() / m_message_size;
}

void Queue::clear_high_water_mark() {
Expand All @@ -59,7 +59,7 @@ void Queue::clear_high_water_mark() {

FwSizeType Queue::getQueueSize() const {
FW_ASSERT(m_message_size > 0, static_cast<FwAssertArgType>(m_message_size));
return static_cast<FwSizeType>(m_internal.get_allocated_size() / m_message_size);
return m_internal.get_allocated_size() / m_message_size;
}


Expand Down

0 comments on commit d636bbf

Please sign in to comment.