Skip to content

Commit eea87bf

Browse files
norbertwgkmilos
authored andcommitted
Suggested changes from kevinbackhouse
1 parent 03802df commit eea87bf

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

app/actions.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,10 +1812,10 @@ int renameFile(std::string& newPath, const tm* tm, Exiv2::ExifData& exifData) {
18121812
auto oldFsPath = fs::path(path);
18131813
std::string format = Params::instance().format_;
18141814
std::string filename = p.stem().string();
1815-
std::string basesuffix;
1816-
int pos = filename.find('.');
1817-
if (pos > 0)
1818-
basesuffix = filename.substr(filename.find('.'));
1815+
std::string basesuffix = "";
1816+
const size_t pos = filename.find('.');
1817+
if (pos != std::string::npos)
1818+
basesuffix = filename.substr(pos);
18191819
replace(format, ":basename:", p.stem().string());
18201820
replace(format, ":basesuffix:", basesuffix);
18211821
replace(format, ":dirname:", p.parent_path().filename().string());
@@ -1832,10 +1832,10 @@ int renameFile(std::string& newPath, const tm* tm, Exiv2::ExifData& exifData) {
18321832
// for concatenation of new file name, concatenation operator of std::filesystem::path is not used:
18331833
// On MSYS2 UCRT64 the path separator to be used in terminal is slash, but as concatenation operator
18341834
// a back slash will be added. Rename works but with verbose a path with different operators will be shown.
1835-
int len = p.parent_path().string().length();
1835+
const size_t len = p.parent_path().string().length();
18361836
std::string parent_path_sep = "";
18371837
if (len > 0)
1838-
parent_path_sep = newPath.substr(0, ++len);
1838+
parent_path_sep = newPath.substr(0, len+1);
18391839

18401840
newPath = parent_path_sep + std::string(basename) + p.extension().string();
18411841

@@ -1851,6 +1851,7 @@ int renameFile(std::string& newPath, const tm* tm, Exiv2::ExifData& exifData) {
18511851
std::regex_token_iterator<std::string::iterator> rend;
18521852
std::regex_token_iterator<std::string::iterator> token(format.begin(), format.end(), format_regex);
18531853
while (token != rend) {
1854+
Exiv2::Internal::enforce<std::overflow_error>(token->str().length() >= 2, "token too short");
18541855
std::string tag = token->str().substr(1, token->str().length() - 2);
18551856
const auto key = exifData.findKey(Exiv2::ExifKey(tag));
18561857
std::string val = "";

0 commit comments

Comments
 (0)