[fpc-devel] stat and nil
Martin Frb
lazarus at mfriebe.de
Sun Oct 4 11:08:11 CEST 2026
Are older Linux versions safe to call stat with a nil pointer?
https://man7.org/linux/man-pages/man2/stat.2.html
> If /path/ is an empty string (or NULL, since Linux 6.11)
(According to google 6.11 is from 2024 / if so, older versions are still
out there)
3.3.1\source\rtl\unix\sysutils.pp
Function DirectoryExists (Const Directory : RawByteString; FollowLink :
Boolean) : Boolean;
Var
Info : Stat;
SystemFileName: RawByteString;
exists: Boolean;
begin
SystemFileName:=ToSingleByteFileSystemEncodedFileName(Directory);
exists:=fpstat(pointer(SystemFileName),Info)>=0;
If the filename is empty, then path is nil.
Valgrind annotates that (even on a new Linux)
==28712== Syscall param stat(file_name) points to unaddressable byte(s)
==28712== at 0x4B2B64: SYSTEM_$$_FPSYSCALL$INT64$INT64$INT64$$INT64
(in /home/me/lazgit/lazarus)
==28712== by 0x4B3884: SYSTEM_$$_FPSTAT$PCHAR$STAT$$LONGINT (in
/home/me/lazgit/lazarus)
==28712== Address 0x0 is not stack'd, malloc'd or (recently) free'd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20261004/f30805cf/attachment.htm>
More information about the fpc-devel
mailing list