PATCH: use correct buf size in cancd

Mikael Magnusson <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <[email protected]>
When path is metafied, it can be longer than PATH_MAX, so use MAXCMDLEN.
Using ztrlen >= PATH_MAX instead of strlen >= MAXCMDLEN is just a minor
optimization to avoid the syscall if we know the path is too long anyway,
but it's not worth doing this extra check on the result of the snprintf
call (probably).
---
 Src/exec.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Src/exec.c b/Src/exec.c
index f5c5e8e077..62f9310fad 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -6417,7 +6417,7 @@ cancd(char *s)
     char *t;
 
     if (*s != '/') {
-	char sbuf[PATH_MAX+1], **cp;
+	char sbuf[MAXCMDLEN], **cp;
 
 	if (cancd2(s))
 	    return s;
@@ -6426,9 +6426,9 @@ cancd(char *s)
 	if (!nocdpath)
 	    for (cp = cdpath; *cp; cp++) {
 		if (**cp) {
-		    if (snprintf(sbuf, PATH_MAX, "%s/%s", *cp, s) >= PATH_MAX)
+		    if (snprintf(sbuf, sizeof(sbuf), "%s/%s", *cp, s) >= sizeof(sbuf))
 			continue;
-		} else if (strlen(s) >= PATH_MAX) {
+		} else if (ztrlen(s) >= PATH_MAX) {
 		    continue;
 		} else {
 		    strcpy(sbuf, s);
-- 
2.38.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.