[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

@@ -2,6 +2,7 @@
#include "local_context.h"
#include "../../poincare/src/layout/string_layout.h"
#include "../../poincare/src/layout/baseline_relative_layout.h"
#include <assert.h>
#include <string.h>
using namespace Shared;
@@ -81,6 +82,16 @@ Sequence& Sequence::operator=(const Sequence& other) {
return *this;
}
uint32_t Sequence::checksum() {
size_t dataLengthInBytes = 3*TextField::maxBufferSize()*sizeof(char);
assert((dataLengthInBytes & 0x3) == 0); // Assert that dataLengthInBytes is a multiple of 4
char data[3*TextField::maxBufferSize()] = {};
strlcpy(data, text(), TextField::maxBufferSize());
strlcpy(data+TextField::maxBufferSize(), firstInitialConditionText(), TextField::maxBufferSize());
strlcpy(data+2*TextField::maxBufferSize(), secondInitialConditionText(), TextField::maxBufferSize());
return Ion::crc32((uint32_t *)data, dataLengthInBytes>>2);
}
const char * Sequence::firstInitialConditionText() {
return m_firstInitialConditionText;
}