Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2026-10

stat and nil

2 messages · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Frb

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

Reply by email

Martin Frb
to Martin Frb

Strange fpstat adds #0, so it should never be nil.

But valgrind said it was

Martin Frb wrote 37 lines
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 https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email