hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 12735a62d1180c2c611d6f294b97959a4659a604
parent e7313818ecb35ace0428dfa097b2de82b6bce357
Author: Sebastian <sebastian@sebsite.pw>
Date:   Fri, 25 Aug 2023 02:48:31 -0400

path: exclude nul terminator from PATH_MAX

On Linux, PATH_MAX is 4096 in C, but this includes the terminating NUL
byte. Hare strings don't have a terminating NUL byte, so it's possible
for a path whose length is PATH_MAX to actually be too long. This is
corrected here by changing PATH_MAX to 4095.

The only place the terminating NUL byte is relevant is syscalls, but rt
provides its own PATH_MAX which is 4096 bytes anyways.

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mpath/+freebsd.ha | 2+-
Mpath/+linux.ha | 2+-
Mpath/README | 2+-
3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/path/+freebsd.ha b/path/+freebsd.ha @@ -7,4 +7,4 @@ export def PATHSEP: u8 = '/'; const pathsepstr: str = "/"; // Maximum length of a file path for this platform. -export def PATH_MAX: size = 4096; +export def PATH_MAX: size = 4095; diff --git a/path/+linux.ha b/path/+linux.ha @@ -7,4 +7,4 @@ export def PATHSEP: u8 = '/'; const pathsepstr: str = "/"; // Maximum length of a file path for this platform. -export def PATH_MAX: size = 4096; +export def PATH_MAX: size = 4095; diff --git a/path/README b/path/README @@ -16,7 +16,7 @@ Assuming that [[PATHSEP]] is '/', "/usr//bin/../bin/./hare/" becomes "/usr/bin/hare" and "../../foo/bar" is unchanged. The buffer object includes an array of length [[PATH_MAX]], which can be -somewhat large; on Linux it's 4096 bytes. You can allocate this on the stack in +somewhat large; on Linux it's 4095 bytes. You can allocate this on the stack in most cases, but you may prefer to allocate it elsewhere depending on your needs. Functions in this module return [[too_long]] if the buffer's capacity would be exceeded.