Skip to content

Commit

Permalink
files: Fix crash with Umlaut dir entries on macOS. #20 (#21)
Browse files Browse the repository at this point in the history
* files: Fix crash with Umlaut dir entries on macOS. #20

* Add changelog entry
  • Loading branch information
roblillack authored Dec 4, 2024
1 parent 350f500 commit e9c3231
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Fix secondary windows to being resizable. ([#15](https://github.com/roblillack/fsviewer/pull/15))
- Fix showing correct free disk space with SI prefixes. ([#17](https://github.com/roblillack/fsviewer/pull/17))
- Fix alpha channel blending for icons everywhere. ([#18](https://github.com/roblillack/fsviewer/pull/18))
- Fix crash when when directory contains Umlaut entries on macOS ([#21](https://github.com/roblillack/fsviewer/pull/21))

## FSViewer 0.2.7 (2024-06-22)

Expand Down
37 changes: 30 additions & 7 deletions src/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,28 @@ char* GetFileExtn(char* filename)
return extn;
}

char* GetFileExtnOrNull(char* filename)
{
if (FSStringMatch("*.tar.gz", filename)) {
return ".tar.gz";
}

char* ext = strrchr(filename, '.');
if (ext == NULL) {
return NULL;
}

for (int i = 0; i < strlen(ext); i++) {
if ((uint)ext[i] > 0x7f) {
// We don't allow non-ASCII characters in file extensions
// see: https://github.com/roblillack/fsviewer/issues/20
return NULL;
}
}

return ext;
}

char* GetFileAbbrev(char* fileName)
{
char* abbrev;
Expand Down Expand Up @@ -353,12 +375,15 @@ char* GetFileImgName(char* fileName, enum FileType fileType)
if (fileName == NULL)
return wstrdup(DEFAULT_STR);

if (fileType == ROOT)
extn = wstrdup("ROOT");
else
extn = wstrdup(GetFileExtn(fileName));
if (fileType == ROOT) {
extn = "ROOT";
} else {
extn = GetFileExtnOrNull(fileName);
}

name = FSGetStringForNameKey(extn, "icon");
if (extn) {
name = FSGetStringForNameKey(extn, "icon");
}

if (name == NULL) {
if (fileType == DIRECTORY)
Expand All @@ -374,8 +399,6 @@ char* GetFileImgName(char* fileName, enum FileType fileType)
icon = LocateImage(name);
if (name)
free(name);
if (extn)
free(extn);

if (icon)
return icon;
Expand Down

0 comments on commit e9c3231

Please sign in to comment.