diff --git a/sycl/source/detail/config.cpp b/sycl/source/detail/config.cpp index 8258bae4ed412..544dce4b2cb76 100644 --- a/sycl/source/detail/config.cpp +++ b/sycl/source/detail/config.cpp @@ -27,7 +27,7 @@ namespace detail { #define CONFIG(Name, MaxSize, CompileTimeDef) \ const char *SYCLConfigBase::MValueFromFile = nullptr; \ - char SYCLConfigBase::MStorage[MaxSize]; \ + char SYCLConfigBase::MStorage[MaxSize + 1]; \ const char *const SYCLConfigBase::MCompileTimeDef = \ getStrOrNullptr(STRINGIFY_LINE(CompileTimeDef)); \ const char *const SYCLConfigBase::MConfigName = STRINGIFY_LINE(Name); @@ -40,6 +40,7 @@ static void initValue(const char *Key, const char *Value) { #define CONFIG(Name, MaxSize, CompileTimeDef) \ if (0 == strncmp(Key, SYCLConfigBase::MConfigName, MAX_CONFIG_NAME)) { \ strncpy(SYCLConfigBase::MStorage, Value, MaxSize); \ + SYCLConfigBase::MStorage[MaxSize] = '\0'; \ SYCLConfigBase::MValueFromFile = SYCLConfigBase::MStorage; \ return; \ } diff --git a/sycl/source/detail/config.hpp b/sycl/source/detail/config.hpp index e1d571d8dfb3d..b1510004be08f 100644 --- a/sycl/source/detail/config.hpp +++ b/sycl/source/detail/config.hpp @@ -63,7 +63,7 @@ template class SYCLConfigBase; public: \ /*Preallocated storage for config value which is extracted from a config \ * file*/ \ - static char MStorage[MaxSize]; \ + static char MStorage[MaxSize + 1]; \ /*Points to the storage if config is set in the file, nullptr otherwise*/ \ static const char *MValueFromFile; \ /*The name of the config*/ \