From 1832800a723fc338add0afaf8e006578a9f02184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 19 Mar 2019 11:06:34 +0100 Subject: [PATCH] [apps/probability] Fix UTF8 problem when copying law parameter In probability, when displaying the exponential law for instance, the lambda did not appear correctly. --- apps/probability/calculation_controller.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/probability/calculation_controller.cpp b/apps/probability/calculation_controller.cpp index 0cbacaa4a..3ce66b908 100644 --- a/apps/probability/calculation_controller.cpp +++ b/apps/probability/calculation_controller.cpp @@ -281,17 +281,20 @@ void CalculationController::updateTitle() { if (currentChar >= k_titleBufferSize) { break; } - m_titleBuffer[currentChar++] = I18n::translate(m_law->parameterNameAtIndex(index))[0]; - strlcpy(m_titleBuffer+currentChar, " = ", k_titleBufferSize - currentChar); - currentChar += 3; + /* strlcpy returns the size of src, not the size copied, but it is not a + * problem here. */ + currentChar += strlcpy(m_titleBuffer+currentChar, I18n::translate(m_law->parameterNameAtIndex(index)), k_titleBufferSize - currentChar); + if (currentChar >= k_titleBufferSize) { + break; + } + currentChar += strlcpy(m_titleBuffer+currentChar, " = ", k_titleBufferSize - currentChar); if (currentChar >= k_titleBufferSize) { break; } constexpr size_t bufferSize = PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits); char buffer[bufferSize]; PrintFloat::convertFloatToText(m_law->parameterValueAtIndex(index), buffer, bufferSize, Constant::ShortNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal); - strlcpy(m_titleBuffer+currentChar, buffer, k_titleBufferSize - currentChar); - currentChar += strlen(buffer); + currentChar += strlcpy(m_titleBuffer+currentChar, buffer, k_titleBufferSize - currentChar); if (currentChar >= k_titleBufferSize) { break; }