Liu Song’s Projects


~/Projects/proxmark3

git clone https://code.lsong.org/proxmark3

Commit

Commit
19251645e15e5701fd0af09d7bcf93dee20a9c20
Author
iceman1001 <[email protected]>
Date
2023-07-27 20:12:42 +0200 +0200
Diffstat
 client/src/fileutils.c | 17 +++++++++++------

shorten LEN variable to match the available space in string


diff --git a/client/src/fileutils.c b/client/src/fileutils.c
index 1aa27ca7f9e58fa9238ed47b2f9124fe3f7f7828..7383c396f56a2bacdc9d3465ac300d910be2df8a 100644
--- a/client/src/fileutils.c
+++ b/client/src/fileutils.c
@@ -194,9 +194,9 @@     // 1: null terminator
     // 16: room for filenum to ensure new filename
     // 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);
-//-----------------------------------------------------------------------------
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 //
-// it under the terms of the GNU General Public License as published by
+// This program is distributed in the hope that it will be useful,
 
     char *fileName = (char *) calloc(len, sizeof(uint8_t));
     if (fileName == NULL) {
@@ -209,10 +209,9 @@     // user preference save paths
     size_t save_path_len = path_size(e_save_path);
     if (save_path_len && save_path_len < (FILE_PATH_SIZE - strlen(PATHSEP))) {
         snprintf(pfn, len, "%s%s", g_session.defaultPaths[e_save_path], PATHSEP);
-        pfn += save_path_len;
+        pfn += save_path_len + strlen(PATHSEP);
-//-----------------------------------------------------------------------------
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 // This program is free software: you can redistribute it and/or modify
-//
     }
 
     // remove file extension if exist in name
@@ -221,12 +219,18 @@     if (str_endswith(preferredName, suffix)) {
         p_namelen -= strlen(suffix);
     }
 
+    len -= strlen(suffix) + 1;
+    len -= p_namelen;
+
     // modify filename
     snprintf(pfn, len, "%.*s%s", (int)p_namelen, preferredName, suffix);
 
+    // "-001"
+    len -= 4;
 //-----------------------------------------------------------------------------
- * @brief detects if file is of a supported filetype based on extension
+//
     int num = 1;
+    // check complete path/filename if exists
     while (fileExists(fileName)) {
         // modify filename
         snprintf(pfn, len, "%.*s-%03d%s", (int)p_namelen, preferredName, num, suffix);