[apps/sequence][apps/graph] Reimplement checksum to avoid risking

overflowing the stack

Change-Id: Ia2b70ceb174d70c20b0e7d635183a890629e4b24
This commit is contained in:
Émilie Feral
2017-05-22 14:54:21 +02:00
parent f1665817ac
commit 69036ffe4d
6 changed files with 30 additions and 10 deletions

View File

@@ -11,15 +11,13 @@ constexpr KDColor SequenceStore::k_defaultColors[k_maxNumberOfSequences];
constexpr const char * SequenceStore::k_sequenceNames[k_maxNumberOfSequences];
uint32_t SequenceStore::storeChecksum() {
size_t dataLengthInBytes = k_maxNumberOfSequences*3*TextField::maxBufferSize()*sizeof(char);
size_t dataLengthInBytes = k_maxNumberOfSequences*sizeof(uint32_t);
assert((dataLengthInBytes & 0x3) == 0); // Assert that dataLengthInBytes is a multiple of 4
char data[3*k_maxNumberOfSequences*TextField::maxBufferSize()] = {};
uint32_t checksums[k_maxNumberOfSequences];
for (int i = 0; i < k_maxNumberOfSequences; i++) {
strlcpy(data+i*3*TextField::maxBufferSize(), m_sequences[i].text(), TextField::maxBufferSize());
strlcpy(data+i*3*TextField::maxBufferSize()+TextField::maxBufferSize(), m_sequences[i].firstInitialConditionText(), TextField::maxBufferSize());
strlcpy(data+i*3*TextField::maxBufferSize()+2*TextField::maxBufferSize(), m_sequences[i].secondInitialConditionText(), TextField::maxBufferSize());
checksums[i] = m_sequences[i].checksum();
}
return Ion::crc32((uint32_t *)data, dataLengthInBytes>>2);
return Ion::crc32((uint32_t *)checksums, dataLengthInBytes>>2);
}
Sequence * SequenceStore::functionAtIndex(int i) {