Skip to content

Commit

Permalink
fix(config): avoid -Wstringop-truncation
Browse files Browse the repository at this point in the history
Fix -Wstringop-truncation in config.c by expanding the length by one to
allow strncpy to null terminate the string.
  • Loading branch information
stevenh committed Sep 28, 2021
1 parent 6bf8835 commit 18bd4cc
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 18bd4cc

Please sign in to comment.