<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
Are older Linux versions safe to call stat with a nil pointer?<br>
<br>
<a class="moz-txt-link-freetext" href="https://man7.org/linux/man-pages/man2/stat.2.html">https://man7.org/linux/man-pages/man2/stat.2.html</a><br>
> If <i>path</i> is an empty string (or NULL, since Linux 6.11)<br>
<br>
(According to google 6.11 is from 2024 / if so, older versions are
still out there)<br>
<br>
<br>
<br>
3.3.1\source\rtl\unix\sysutils.pp<br>
<br>
Function DirectoryExists (Const Directory : RawByteString;
FollowLink : Boolean) : Boolean;<br>
Var<br>
Info : Stat;<br>
SystemFileName: RawByteString;<br>
exists: Boolean;<br>
begin<br>
SystemFileName:=ToSingleByteFileSystemEncodedFileName(Directory);<br>
exists:=fpstat(pointer(SystemFileName),Info)>=0;<br>
<br>
<br>
If the filename is empty, then path is nil.<br>
<br>
Valgrind annotates that (even on a new Linux)<br>
==28712== Syscall param stat(file_name) points to unaddressable
byte(s)<br>
==28712== at 0x4B2B64:
SYSTEM_$$_FPSYSCALL$INT64$INT64$INT64$$INT64 (in
/home/me/lazgit/lazarus)<br>
==28712== by 0x4B3884: SYSTEM_$$_FPSTAT$PCHAR$STAT$$LONGINT (in
/home/me/lazgit/lazarus)<br>
==28712== Address 0x0 is not stack'd, malloc'd or (recently) free'd<br>
<br>
</body>
</html>