diff --git a/apps/sequence/sequence.cpp b/apps/sequence/sequence.cpp index cb4470ea6..5c754009d 100644 --- a/apps/sequence/sequence.cpp +++ b/apps/sequence/sequence.cpp @@ -83,13 +83,11 @@ Sequence& Sequence::operator=(const Sequence& other) { } 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()] = {}; + char data[k_dataLengthInBytes/sizeof(char)] = {}; 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); + return Ion::crc32((uint32_t *)data, k_dataLengthInBytes>>2); } const char * Sequence::firstInitialConditionText() { diff --git a/apps/sequence/sequence.h b/apps/sequence/sequence.h index e794192b4..e24847d68 100644 --- a/apps/sequence/sequence.h +++ b/apps/sequence/sequence.h @@ -43,6 +43,8 @@ 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)+2; + 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; char m_firstInitialConditionText[TextField::maxBufferSize()]; diff --git a/apps/shared/function.cpp b/apps/shared/function.cpp index c53c70e88..7e73f7fd2 100644 --- a/apps/shared/function.cpp +++ b/apps/shared/function.cpp @@ -27,11 +27,9 @@ Function& Function::operator=(const Function& other) { } uint32_t Function::checksum() { - size_t dataLengthInBytes = TextField::maxBufferSize()*sizeof(char); - assert((dataLengthInBytes & 0x3) == 0); // Assert that dataLengthInBytes is a multiple of 4 - char data[TextField::maxBufferSize()] = {}; + char data[k_dataLengthInBytes/sizeof(char)] = {}; strlcpy(data, m_text, TextField::maxBufferSize()); - return Ion::crc32((uint32_t *)data, dataLengthInBytes>>2); + return Ion::crc32((uint32_t *)data, k_dataLengthInBytes>>2); } void Function::setContent(const char * c) { diff --git a/apps/shared/function.h b/apps/shared/function.h index 1483d28a0..1acdae8ef 100644 --- a/apps/shared/function.h +++ b/apps/shared/function.h @@ -32,6 +32,8 @@ public: protected: mutable Poincare::Expression * m_expression; private: + constexpr static size_t k_dataLengthInBytes = TextField::maxBufferSize()*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()]; const char * m_name;