shorten LEN variable to match the available space in string
This commit is contained in:
1 parent
a44e2fbc36
commit
19251645e1
1 file changed
+10
-4
+10
-4
@@ -194,7 +194,7 @@ char *newfilenamemcopyEx(const char *preferredName, const char *suffix, savePath
|
|||||||
// 16: room for filenum to ensure new filename
|
// 16: room for filenum to ensure new filename
|
||||||
// save_path_len + strlen(PATHSEP): the user preference save paths
|
// save_path_len + strlen(PATHSEP): the user preference save paths
|
||||||
//const size_t len = p_namelen + strlen(suffix) + 1 + 16 + save_path_len + strlen(PATHSEP);
|
//const size_t len = p_namelen + strlen(suffix) + 1 + 16 + save_path_len + strlen(PATHSEP);
|
||||||
const size_t len = FILE_PATH_SIZE;
|
size_t len = FILE_PATH_SIZE;
|
||||||
|
|
||||||
char *fileName = (char *) calloc(len, sizeof(uint8_t));
|
char *fileName = (char *) calloc(len, sizeof(uint8_t));
|
||||||
if (fileName == NULL) {
|
if (fileName == NULL) {
|
||||||
@@ -207,8 +207,8 @@ char *newfilenamemcopyEx(const char *preferredName, const char *suffix, savePath
|
|||||||
size_t save_path_len = path_size(e_save_path);
|
size_t save_path_len = path_size(e_save_path);
|
||||||
if (save_path_len && save_path_len < (FILE_PATH_SIZE - strlen(PATHSEP))) {
|
if (save_path_len && save_path_len < (FILE_PATH_SIZE - strlen(PATHSEP))) {
|
||||||
snprintf(pfn, len, "%s%s", g_session.defaultPaths[e_save_path], PATHSEP);
|
snprintf(pfn, len, "%s%s", g_session.defaultPaths[e_save_path], PATHSEP);
|
||||||
pfn += save_path_len;
|
pfn += save_path_len + strlen(PATHSEP);
|
||||||
pfn += strlen(PATHSEP);
|
len -= save_path_len + strlen(PATHSEP);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove file extension if exist in name
|
// remove file extension if exist in name
|
||||||
@@ -217,11 +217,17 @@ char *newfilenamemcopyEx(const char *preferredName, const char *suffix, savePath
|
|||||||
p_namelen -= strlen(suffix);
|
p_namelen -= strlen(suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
len -= strlen(suffix) + 1;
|
||||||
|
len -= p_namelen;
|
||||||
|
|
||||||
// modify filename
|
// modify filename
|
||||||
snprintf(pfn, len, "%.*s%s", (int)p_namelen, preferredName, suffix);
|
snprintf(pfn, len, "%.*s%s", (int)p_namelen, preferredName, suffix);
|
||||||
|
|
||||||
// check complete path/filename if exists
|
// "-001"
|
||||||
|
len -= 4;
|
||||||
|
|
||||||
int num = 1;
|
int num = 1;
|
||||||
|
// check complete path/filename if exists
|
||||||
while (fileExists(fileName)) {
|
while (fileExists(fileName)) {
|
||||||
// modify filename
|
// modify filename
|
||||||
snprintf(pfn, len, "%.*s-%03d%s", (int)p_namelen, preferredName, num, suffix);
|
snprintf(pfn, len, "%.*s-%03d%s", (int)p_namelen, preferredName, num, suffix);
|
||||||
|
|||||||
Reference in new issue
Block a user