diff --git a/lib/areadlink-with-size.c b/lib/areadlink-with-size.c index eacad3f..2fbe51c 100644 --- a/lib/areadlink-with-size.c +++ b/lib/areadlink-with-size.c @@ -36,14 +36,15 @@ check, so it's OK to guess too small on hosts where there is no arbitrary limit to symbolic link length. */ #ifndef SYMLINK_MAX -# define SYMLINK_MAX 1024 +# define SYMLINK_MAX 1023 #endif #define MAXSIZE (SIZE_MAX < SSIZE_MAX ? SIZE_MAX : SSIZE_MAX) /* Call readlink to get the symbolic link value of FILE. SIZE is a hint as to how long the link is expected to be; - typically it is taken from st_size. It need not be correct. + typically it is taken from st_size. It need not be correct, + and a value of 0 (or more than 8Ki) will select an appropriate lower bound. Return a pointer to that NUL-terminated string in malloc'd storage. If readlink fails, malloc fails, or if the link value is longer than SSIZE_MAX, return NULL (caller may use errno to diagnose). */ @@ -61,7 +62,7 @@ areadlink_with_size (char const *file, size_t size) : INITIAL_LIMIT_BOUND); /* The initial buffer size for the link value. */ - size_t buf_size = size < initial_limit ? size + 1 : initial_limit; + size_t buf_size = size && size < initial_limit ? size + 1 : initial_limit; while (1) {