diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-10-07 15:19:19 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-10-09 17:27:27 +0300 |
commit | bc6f439e94a56be4e52e588593a0d8003f8d65e5 (patch) | |
tree | e12667527ce5c914eaea3229f1f113f299afaed3 /extern/cuew/src | |
parent | a630e46a5827184b2f15f02a3ec375e5d4f377f6 (diff) |
CUDA Wrangler: Fix strict compiler warning
Namely addresses -Wstringop-truncation
Not sure if there is anything to be done for strncpy.
Differential Revision: https://developer.blender.org/D6006
Diffstat (limited to 'extern/cuew/src')
-rw-r--r-- | extern/cuew/src/cuew.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/extern/cuew/src/cuew.c b/extern/cuew/src/cuew.c index 1f386c4e5d3..a0146741494 100644 --- a/extern/cuew/src/cuew.c +++ b/extern/cuew/src/cuew.c @@ -859,6 +859,23 @@ int cuewNvrtcVersion(void) { return 0; } +static size_t safe_strnlen(const char *s, size_t maxlen) { + size_t length; + for (length = 0; length < maxlen; s++, length++) { + if (*s == '\0') { + break; + } + } + return length; +} + +static char *safe_strncpy(char *dest, const char *src, size_t n) { + const size_t src_len = safe_strnlen(src, n - 1); + memcpy(dest, src, src_len); + dest[src_len] = '\0'; + return dest; +} + int cuewCompilerVersion(void) { const char *path = cuewCompilerPath(); const char *marker = "Cuda compilation tools, release "; @@ -874,7 +891,7 @@ int cuewCompilerVersion(void) { } /* get --version output */ - strncpy(command, path, sizeof(command)); + safe_strncpy(command, path, sizeof(command)); strncat(command, " --version", sizeof(command) - strlen(path)); pipe = popen(command, "r"); if (!pipe) { |