From 5f02be00bca1a5821383c9593ffbd4155c6ef27e Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Sat, 11 Dec 1999 14:48:24 +0000 Subject: [PATCH] While comparing this with OpenBSD (ie: trying to figure out what mkstemps() is good for... :-)), I discovered that part of the change when mkstemps() was brought in was missed - it was missing the termination case to make sure it doesn't walk into the suffix. This isn't the same code OpenBSD has, I think this is a little better as we terminate the loop in a better spot. --- lib/libc/stdio/mktemp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/libc/stdio/mktemp.c b/lib/libc/stdio/mktemp.c index af547c618ff..cd24449410f 100644 --- a/lib/libc/stdio/mktemp.c +++ b/lib/libc/stdio/mktemp.c @@ -111,7 +111,6 @@ _gettemp(path, doopen, domkdir, slen) return(0); } - pid = getpid(); for (trv = path; *trv; ++trv) ; trv -= slen; @@ -121,6 +120,7 @@ _gettemp(path, doopen, domkdir, slen) errno = EINVAL; return (0); } + pid = getpid(); while (*trv == 'X' && pid != 0) { *trv-- = (pid % 10) + '0'; pid /= 10; @@ -177,7 +177,7 @@ _gettemp(path, doopen, domkdir, slen) /* tricky little algorithm for backward compatibility */ for (trv = start;;) { - if (!*trv) + if (*trv == '\0' || trv == suffp) return(0); if (*trv == 'Z') *trv++ = 'a';