Skip to content

Commit 30752bb

Browse files
committed
bugfix: zfile changes caused exceptions if the filename had no extension
1 parent 0c14f47 commit 30752bb

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

src/zfile.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,25 +1975,27 @@ static struct zfile *zfile_fopenx2 (const TCHAR *name, const TCHAR *mode, int ma
19751975
return NULL;
19761976
#ifdef AMIBERRY
19771977
const auto name_string = std::string(name);
1978-
1979-
// capitalize file extension then try again
1980-
std::string ext = name_string.substr(name_string.find_last_of('.'));
1981-
if (!ext.empty()) {
1982-
std::transform(ext.begin(), ext.end(), ext.begin(), ::toupper);
1983-
const std::string tmp_upper = name_string.substr(0, name_string.find_last_of('.')) + ext;
1984-
f = zfile_fopen_x(tmp_upper.c_str(), mode, mask, index);
1985-
if (f)
1986-
return f;
1987-
}
1988-
1989-
// lowercase file extension then try again
1990-
ext = name_string.substr(name_string.find_last_of('.'));
1991-
if (!ext.empty()) {
1992-
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
1993-
const std::string tmp_lower = name_string.substr(0, name_string.find_last_of('.')) + ext;
1994-
f = zfile_fopen_x(tmp_lower.c_str(), mode, mask, index);
1995-
if (f)
1996-
return f;
1978+
const auto dot_pos = name_string.find_last_of('.');
1979+
if (dot_pos != std::string::npos) {
1980+
// capitalize file extension then try again
1981+
std::string ext = name_string.substr(dot_pos);
1982+
if (!ext.empty()) {
1983+
std::transform(ext.begin(), ext.end(), ext.begin(), ::toupper);
1984+
const std::string tmp_upper = name_string.substr(0, name_string.find_last_of('.')) + ext;
1985+
f = zfile_fopen_x(tmp_upper.c_str(), mode, mask, index);
1986+
if (f)
1987+
return f;
1988+
}
1989+
1990+
// lowercase file extension then try again
1991+
ext = name_string.substr(dot_pos);
1992+
if (!ext.empty()) {
1993+
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
1994+
const std::string tmp_lower = name_string.substr(0, name_string.find_last_of('.')) + ext;
1995+
f = zfile_fopen_x(tmp_lower.c_str(), mode, mask, index);
1996+
if (f)
1997+
return f;
1998+
}
19971999
}
19982000
#endif
19992001
if (name[1] != ':') {

0 commit comments

Comments
 (0)