[apps/sequence][apps/graph] Checksum takes into account whether the

function is active and its name

Change-Id: I790d9a793c512a686f21f1db4fc0848a16baea5c
This commit is contained in:
Émilie Feral
2017-05-29 11:41:39 +02:00
parent 1966b4648c
commit 832af9f9f4
4 changed files with 7 additions and 2 deletions

View File

@@ -87,6 +87,9 @@ uint32_t Sequence::checksum() {
strlcpy(data, text(), TextField::maxBufferSize());
strlcpy(data+TextField::maxBufferSize(), firstInitialConditionText(), TextField::maxBufferSize());
strlcpy(data+2*TextField::maxBufferSize(), secondInitialConditionText(), TextField::maxBufferSize());
data[k_dataLengthInBytes-3] = (char)m_type;
data[k_dataLengthInBytes-2] = name()!= nullptr ? name()[0] : 0;
data[k_dataLengthInBytes-1] = isActive() ? 1 : 0;
return Ion::crc32((uint32_t *)data, k_dataLengthInBytes>>2);
}

View File

@@ -43,7 +43,7 @@ public:
private:
constexpr static int k_maxRecurrentRank = 10000;
constexpr static float k_maxNumberOfTermsInSum = 100000.0f;
constexpr static size_t k_dataLengthInBytes = 3*TextField::maxBufferSize()*sizeof(char);
constexpr static size_t k_dataLengthInBytes = (3*TextField::maxBufferSize()+3)*sizeof(char)+1;
static_assert((k_dataLengthInBytes & 0x3) == 0, "The sequence data size is not a multiple of 4 bytes (cannot compute crc)"); // Assert that dataLengthInBytes is a multiple of 4
char symbol() const override;
Type m_type;

View File

@@ -29,6 +29,8 @@ Function& Function::operator=(const Function& other) {
uint32_t Function::checksum() {
char data[k_dataLengthInBytes/sizeof(char)] = {};
strlcpy(data, m_text, TextField::maxBufferSize());
data[k_dataLengthInBytes-2] = m_name != nullptr ? m_name[0] : 0;
data[k_dataLengthInBytes-1] = m_active ? 1 : 0;
return Ion::crc32((uint32_t *)data, k_dataLengthInBytes>>2);
}

View File

@@ -32,7 +32,7 @@ public:
protected:
mutable Poincare::Expression * m_expression;
private:
constexpr static size_t k_dataLengthInBytes = TextField::maxBufferSize()*sizeof(char);
constexpr static size_t k_dataLengthInBytes = (TextField::maxBufferSize()+2)*sizeof(char)+2;
static_assert((k_dataLengthInBytes & 0x3) == 0, "The function data size is not a multiple of 4 bytes (cannot compute crc)"); // Assert that dataLengthInBytes is a multiple of 4
virtual char symbol() const = 0;
char m_text[TextField::maxBufferSize()];