Skip to content

Commit 464f001

Browse files
committed
Address FIXMEs
1 parent 1f859ab commit 464f001

7 files changed

Lines changed: 35 additions & 10 deletions

File tree

Os/File.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,11 @@ File::Status File::incrementalCrc(FwSizeType& size) {
237237
status = this->read(this->m_crc_buffer, size, File::WaitType::NO_WAIT);
238238
if (OP_OK == status) {
239239
FW_ASSERT(size <= FW_FILE_CHUNK_SIZE, FwAssertArgType(size));
240-
// FIXME: Use Utils::Hash wrapper instead of directly using CRC-32 implementation
241-
this->m_crc = Utils::crc32_ieee802_3_update(this->m_crc_buffer, size, this->m_crc);
240+
Utils::Hash hash;
241+
hash.setHashValue(U32(~this->m_crc));
242+
hash.update(this->m_crc_buffer, size);
243+
U32 crc;
244+
hash.finalize(crc) this->m_crc = ~crc;
242245
}
243246
}
244247
return status;

Os/test/ut/file/FileRules.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,24 @@ void Os::Test::FileTest::Tester::shadow_flush() {
8080
}
8181

8282
void Os::Test::FileTest::Tester::shadow_crc(U32& crc) {
83+
Utils::Hash hash;
84+
hash.setHashValue(U32(~this->m_independent_crc));
85+
hash.update(this->m_crc_buffer, size);
86+
8387
crc = this->m_independent_crc;
8488
SyntheticFileData& data = *reinterpret_cast<SyntheticFileData*>(this->m_shadow.getHandle());
8589

8690
// Calculate CRC on full file starting at m_pointer
8791
for (FwSizeType i = data.m_pointer; i < data.m_data.size();
8892
i++, this->m_shadow.seek(1, Os::File::SeekType::RELATIVE)) {
89-
// FIXME: Use Utils::Hash wrapper instead of directly using CRC-32 implementation
9093
U8 byte = data.m_data.at(i);
91-
crc = Utils::crc32_ieee802_3_update(&byte, sizeof(byte), crc);
94+
hash.update(&byte, sizeof(byte));
9295
}
9396
// Update tracking variables
94-
this->m_independent_crc = Os::File::INITIAL_CRC;
97+
U32 crcFinal;
98+
hash.finalize(crcFinal);
99+
crc = ~crcFinal;
100+
this->m_independent_crc = crc;
95101
}
96102

97103
void Os::Test::FileTest::Tester::shadow_partial_crc(FwSizeType& size) {
@@ -102,9 +108,16 @@ void Os::Test::FileTest::Tester::shadow_partial_crc(FwSizeType& size) {
102108
std::min(static_cast<FwSizeType>(data.m_pointer) + size, static_cast<FwSizeType>(data.m_data.size()));
103109
size = (data.m_pointer >= bound) ? 0 : static_cast<FwSizeType>(bound - data.m_pointer);
104110
for (FwSizeType i = data.m_pointer; i < bound; i++) {
105-
// FIXME: Use Utils::Hash wrapper instead of directly using CRC-32 implementation
106111
U8 byte = data.m_data.at(i);
107-
this->m_independent_crc = Utils::crc32_ieee802_3_update(&byte, sizeof(byte), this->m_independent_crc);
112+
113+
Utils::Hash hash;
114+
hash.setHashValue(U32(~this->m_independent_crc));
115+
hash.update(&byte, sizeof(byte));
116+
117+
U32 crcFinal;
118+
hash.finalize(crcFinal);
119+
this->m_independent_crc = ~crcFinal;
120+
108121
this->m_shadow.seek(1, Os::File::SeekType::RELATIVE);
109122
}
110123
}

Svc/FpySequencer/test/ut/FpySequencerTester.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ void FpySequencerTester::tester_set_m_statementsDispatched(U64 val) {
650650
}
651651

652652
void FpySequencerTester::tester_set_m_computedCRC(U32 crc) {
653-
this->cmp.m_computedCRC.setHashValue(~crc);
653+
this->cmp.m_computedCRC.setHashValue(U32(~crc));
654654
}
655655

656656
// Get cmp member pointers

Svc/PrmDb/PrmDbImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void PrmDbImpl::PRM_SAVE_FILE_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) {
138138
// write placeholder for the CRC
139139
Utils::Hash crc;
140140
FwSizeType writeSize = static_cast<FwSizeType>(HASH_DIGEST_LENGTH);
141-
U32 crcInitial = ~0;
141+
U32 crcInitial = U32(~0);
142142
stat = paramFile.write(reinterpret_cast<const U8*>(&crcInitial), writeSize, Os::File::WaitType::WAIT);
143143

144144
if (stat != Os::File::OP_OK) {

Utils/Hash/Crc32/HashImpl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,8 @@ void Hash ::setHashValue(HashBuffer& value) {
5858
this->hash_handle = ~this->hash_handle;
5959
}
6060

61+
void Hash ::setHashValue(U32 value) {
62+
this->hash_handle = ~value;
63+
}
64+
6165
} // namespace Utils

Utils/Hash/Crc32/test/ut/Crc32Test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ TEST(Crc32Test, testHelloWorld) {
3636
TEST(Crc32Test, testBinary) {
3737
U8 input[256];
3838
for (U32 i = 0; i < sizeof(input); i++) {
39-
input[i] = i;
39+
input[i] = U8(i);
4040
}
4141

4242
Utils::HashBuffer hb;

Utils/Hash/Hash.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ class Hash {
6262
void setHashValue(HashBuffer& value //! Hash value
6363
);
6464

65+
//! Set hash value to specified value
66+
//!
67+
void Hash ::setHashValue(U32 value //! Hash value
68+
);
69+
6570
//! Update an incremental computation with new data
6671
//! \param data: pointer to start of data to add to hash calculation
6772
//! \param len: length of data to add to hash calculation

0 commit comments

Comments
 (0)