[fpc-devel] stat and nil
Martin Frb
lazarus at mfriebe.de
Sun Oct 4 11:21:18 CEST 2026
Strange fpstat adds #0, so it should never be nil.
But valgrind said it was
On 04/10/2026 11:08, Martin Frb via fpc-devel wrote:
> 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
>
>
> _______________________________________________
> fpc-devel maillist -fpc-devel at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20261004/8fb8de9e/attachment.htm>
More information about the fpc-devel
mailing list