Skip to content

Commit 22bb757

Browse files
yangflNikolajSchlej
authored andcommitted
Remove PATH_MAX from realpath
POSIX.1-2008 ensures realpath() give a dynamically allocated buffer if NULL is passed, which avoids using PATH_MAX, which may be too large to fit in stack, or even undefined on some systems.
1 parent d61d759 commit 22bb757

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

common/filesystem.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,14 @@ bool changeDirectory(const UString & dir)
100100
}
101101

102102
UString getAbsPath(const UString & path) {
103-
char abs[PATH_MAX] = {};
103+
char * abs = realpath(path.toLocal8Bit(), nullptr);
104104
// Last is a non-standard extension for non-existent files
105-
if (realpath(path.toLocal8Bit(), abs) || abs[0] != '\0')
106-
return UString(abs);
107-
return path;
105+
UString new_path;
106+
if (abs)
107+
new_path = UString(abs);
108+
else
109+
new_path = path;
110+
free(abs);
111+
return new_path;
108112
}
109113
#endif

0 commit comments

Comments
 (0)