[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

@@ -1,6 +1,7 @@
#include "function.h"
#include <string.h>
#include <math.h>
#include <assert.h>
using namespace Poincare;
@@ -25,6 +26,14 @@ Function& Function::operator=(const Function& other) {
return *this;
}
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()] = {};
strlcpy(data, m_text, TextField::maxBufferSize());
return Ion::crc32((uint32_t *)data, dataLengthInBytes>>2);
}
void Function::setContent(const char * c) {
strlcpy(m_text, c, sizeof(m_text));
if (m_layout != nullptr) {