From 18bd4cc4c34dfe091226b0316becf64d46beb770 Mon Sep 17 00:00:00 2001 From: Steven Hartland Date: Fri, 18 Jun 2021 23:31:15 +0100 Subject: [PATCH] fix(config): avoid -Wstringop-truncation Fix -Wstringop-truncation in config.c by expanding the length by one to allow strncpy to null terminate the string. --- config.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config.c b/config.c index fbda6819..b5732b14 100644 --- a/config.c +++ b/config.c @@ -208,13 +208,12 @@ qsc_load_default_config_files() var = getenv("HOME"); if ((var != NULL) && (var[0] != '\0')) { - int len = strlen(var); + int len = strlen(var) + 1; if (len > PATH_MAX - strlen(HOME_CONFIG_FILE) + 2) { fprintf(stderr, "Path for HOME \"%s\" too long\n", var); return (-1); } strncpy(path, var, len); - path[len] = '\0'; strcat(path, SEP HOME_CONFIG_FILE); rc = try_load_config_file(path, 0); if ((rc == 0) || (rc == -1)) {