Fix regression in BLI_path_suffix for long extensions

Changes from [0] passed in a pointer size to BLI_strncpy.

[0]: f8e23e495b
This commit is contained in:
Campbell Barton
2023-04-20 11:18:26 +10:00
parent f87e474af0
commit 80edd10168
2 changed files with 6 additions and 1 deletions

View File

@@ -596,7 +596,7 @@ bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char
if (string_len + sep_len + suffix_len >= maxlen) {
return false;
}
BLI_strncpy(extension_copy, string + string_end, sizeof(extension));
BLI_strncpy(extension_copy, string + string_end, sizeof(extension_copy));
BLI_sprintf(string + string_end, "%s%s%s", sep, suffix, extension_copy);
return true;
}

View File

@@ -1010,6 +1010,11 @@ TEST(path_util, PathSuffix)
PATH_SUFFIX("", FILE_MAX, "_", "123", true, "_123");
/* Empty input/output. */
PATH_SUFFIX("", FILE_MAX, "", "", true, "");
/* Long suffix. */
PATH_SUFFIX("file.txt", FILE_MAX, "_", "1234567890", true, "file_1234567890.txt");
/* Long extension. */
PATH_SUFFIX("file.txt1234567890", FILE_MAX, "_", "123", true, "file_123.txt1234567890");
}
#undef PATH_SUFFIX