Skip to content

Commit 0c58a78

Browse files
authored
[SYCL][NFC] Fix GCC 8 compilation warnings (#1631)
GCC 8 introduces a warning when strncpy may truncate a string, leaving it without the terminating NULL character [-Wstringop-truncation]. To guarantee that the terminator is present: - increase the size of the target buffer by 1; - set the last character of the buffer to NULL. Signed-off-by: Andrea Bocci <[email protected]>
1 parent 7d4e0ed commit 0c58a78

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

sycl/source/detail/config.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace detail {
2727

2828
#define CONFIG(Name, MaxSize, CompileTimeDef) \
2929
const char *SYCLConfigBase<Name>::MValueFromFile = nullptr; \
30-
char SYCLConfigBase<Name>::MStorage[MaxSize]; \
30+
char SYCLConfigBase<Name>::MStorage[MaxSize + 1]; \
3131
const char *const SYCLConfigBase<Name>::MCompileTimeDef = \
3232
getStrOrNullptr(STRINGIFY_LINE(CompileTimeDef)); \
3333
const char *const SYCLConfigBase<Name>::MConfigName = STRINGIFY_LINE(Name);
@@ -40,6 +40,7 @@ static void initValue(const char *Key, const char *Value) {
4040
#define CONFIG(Name, MaxSize, CompileTimeDef) \
4141
if (0 == strncmp(Key, SYCLConfigBase<Name>::MConfigName, MAX_CONFIG_NAME)) { \
4242
strncpy(SYCLConfigBase<Name>::MStorage, Value, MaxSize); \
43+
SYCLConfigBase<Name>::MStorage[MaxSize] = '\0'; \
4344
SYCLConfigBase<Name>::MValueFromFile = SYCLConfigBase<Name>::MStorage; \
4445
return; \
4546
}

sycl/source/detail/config.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ template <ConfigID Config> class SYCLConfigBase;
6363
public: \
6464
/*Preallocated storage for config value which is extracted from a config \
6565
* file*/ \
66-
static char MStorage[MaxSize]; \
66+
static char MStorage[MaxSize + 1]; \
6767
/*Points to the storage if config is set in the file, nullptr otherwise*/ \
6868
static const char *MValueFromFile; \
6969
/*The name of the config*/ \

0 commit comments

Comments
 (0)