From f81e221f50bb3c0f09e32f56af889e400d0faecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 23 Nov 2018 14:13:55 +0100 Subject: [PATCH] [apps/shared] Fix char buffer initialization (make it const) --- apps/shared/storage_function.cpp | 9 ++++++--- apps/shared/storage_function.h | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/shared/storage_function.cpp b/apps/shared/storage_function.cpp index 4af8a475f..afb572634 100644 --- a/apps/shared/storage_function.cpp +++ b/apps/shared/storage_function.cpp @@ -9,7 +9,7 @@ using namespace Poincare; namespace Shared { -char StorageFunction::k_parenthesedArgument[]("(x)"); +constexpr char StorageFunction::k_parenthesedArgument[]; bool StorageFunction::BaseNameCompliant(const char * baseName, NameNotCompliantError * error) { assert(baseName[0] != 0); @@ -62,9 +62,12 @@ void StorageFunction::setActive(bool active) { int StorageFunction::nameWithArgument(char * buffer, size_t bufferSize, char arg) { const char * functionName = fullName(); - k_parenthesedArgument[1] = arg; size_t baseNameLength = SymbolAbstract::TruncateExtension(buffer, functionName, bufferSize - k_parenthesedArgumentLength); - return baseNameLength + strlcpy(&buffer[baseNameLength], k_parenthesedArgument, bufferSize-baseNameLength); + int result = baseNameLength + strlcpy(&buffer[baseNameLength], k_parenthesedArgument, bufferSize-baseNameLength); + if (baseNameLength+1 < bufferSize - 1) { + buffer[baseNameLength+1] = arg; + } + return result; } template diff --git a/apps/shared/storage_function.h b/apps/shared/storage_function.h index 18a3591f6..954146fdc 100644 --- a/apps/shared/storage_function.h +++ b/apps/shared/storage_function.h @@ -15,7 +15,7 @@ public: ReservedName }; constexpr static int k_parenthesedArgumentLength = 3; - static char k_parenthesedArgument[k_parenthesedArgumentLength+1]; + static constexpr char k_parenthesedArgument[k_parenthesedArgumentLength+1] = "(x)"; constexpr static int k_maxNameWithArgumentSize = Poincare::SymbolAbstract::k_maxNameSize + k_parenthesedArgumentLength; /* Function name and null-terminating char + "(x)" */; static bool BaseNameCompliant(const char * baseName, NameNotCompliantError * error = nullptr);