From 1e9e8023b3bbcbf0a0482bed46c50557c00cb163 Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Tue, 12 May 2015 22:42:39 +0200 Subject: [PATCH] Fix my_searchenv(). --- util.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/util.c b/util.c index a4cb82e..27a2e06 100644 --- a/util.c +++ b/util.c @@ -131,7 +131,9 @@ void my_searchenv( { char *env; char *envcopy; + char *envcopy2; char *cp; + char *last; *hitfile = 0; /* Default failure indication */ @@ -157,7 +159,8 @@ void my_searchenv( argument. I don't want the return value from getenv destroyed. */ - while ((cp = strtok(envcopy, PATHSEP)) != NULL) { + envcopy2 = envcopy; + while ((cp = strtok_r(envcopy2, PATHSEP, &last)) != NULL) { struct stat info; char *concat = malloc(strlen(cp) + strlen(name) + 2); @@ -177,6 +180,7 @@ void my_searchenv( free(envcopy); return; } + envcopy2 = NULL; } /* If I fall out of that loop, then hitfile indicates no match,