git: abed32f91d01 - main - realpath(3): Minor style issues.

From: Dag-Erling Smørgrav <des_at_FreeBSD.org>
Date: Wed, 18 Sep 2024 16:30:15 UTC
The branch main has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=abed32f91d01d91faa709622e3279e9baec37272

commit abed32f91d01d91faa709622e3279e9baec37272
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2024-09-18 16:29:55 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2024-09-18 16:29:55 +0000

    realpath(3): Minor style issues.
    
    Sponsored by:   Klara, Inc.
    Reviewed by:    kevans
    Differential Revision:  https://reviews.freebsd.org/D46695
---
 lib/libc/stdlib/realpath.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/lib/libc/stdlib/realpath.c b/lib/libc/stdlib/realpath.c
index 554d70b43a29..28348ea9e226 100644
--- a/lib/libc/stdlib/realpath.c
+++ b/lib/libc/stdlib/realpath.c
@@ -33,10 +33,10 @@
 #include <sys/stat.h>
 
 #include <errno.h>
+#include <fcntl.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <ssp/ssp.h>
 #include "un-namespace.h"
 #include "libc_private.h"
@@ -146,13 +146,14 @@ realpath1(const char *path, char *resolved)
 				return (NULL);
 			}
 			slen = readlink(resolved, symlink, sizeof(symlink));
-			if (slen <= 0 || slen >= (ssize_t)sizeof(symlink)) {
-				if (slen < 0)
-					; /* keep errno from readlink(2) call */
-				else if (slen == 0)
-					errno = ENOENT;
-				else
-					errno = ENAMETOOLONG;
+			if (slen < 0)
+				return (NULL);
+			if (slen == 0) {
+				errno = ENOENT;
+				return (NULL);
+			}
+			if ((size_t)slen >= sizeof(symlink)) {
+				errno = ENAMETOOLONG;
 				return (NULL);
 			}
 			symlink[slen] = '\0';
@@ -173,7 +174,7 @@ realpath1(const char *path, char *resolved)
 			 */
 			if (p != NULL) {
 				if (symlink[slen - 1] != '/') {
-					if (slen + 1 >= (ssize_t)sizeof(symlink)) {
+					if ((size_t)slen + 1 >= sizeof(symlink)) {
 						errno = ENAMETOOLONG;
 						return (NULL);
 					}