From 2d4e36b98c0c127ef68b24fadc8d3e7ca5e8f23a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Mon, 30 Jul 2018 14:47:41 +0200 Subject: [PATCH] [apps/calc] Handle alloc failure when computing calculation height --- apps/calculation/calculation.cpp | 6 ++++++ apps/calculation/calculation.h | 1 + 2 files changed, 7 insertions(+) diff --git a/apps/calculation/calculation.cpp b/apps/calculation/calculation.cpp index b4a98e653..af4b8b18b 100644 --- a/apps/calculation/calculation.cpp +++ b/apps/calculation/calculation.cpp @@ -70,6 +70,12 @@ void Calculation::setContent(const char * c, Context * context, Expression * ans KDCoordinate Calculation::height(Context * context) { if (m_height < 0) { LayoutRef inputLayout = createInputLayout(); + if (inputLayout.isAllocationFailure()) { + /* If there is not enough tree pool space to create the layout, return a + * default height. Do not store it in m_height in case some memory get + * freed afterwards. */ + return k_heightComputationFailureHeight; + } KDCoordinate inputHeight = inputLayout.layoutSize().height(); LayoutRef approximateLayout = createApproximateOutputLayout(context); KDCoordinate approximateOutputHeight = approximateLayout.layoutSize().height(); diff --git a/apps/calculation/calculation.h b/apps/calculation/calculation.h index f626207a5..7e3325780 100644 --- a/apps/calculation/calculation.h +++ b/apps/calculation/calculation.h @@ -40,6 +40,7 @@ public: EqualSign exactAndApproximateDisplayedOutputsAreEqual(Poincare::Context * context); constexpr static int k_printedExpressionSize = 2*::TextField::maxBufferSize(); private: + static constexpr KDCoordinate k_heightComputationFailureHeight = 50; /* Buffers holding text expressions have to be longer than the text written * by user (of maximum length TextField::maxBufferSize()) because when we * print an expression we add omitted signs (multiplications, parenthesis...) */