From ecaf50c0158bf2d9a0ab02c4cfd50f01289e5d8b Mon Sep 17 00:00:00 2001 From: Javier Olaechea Date: Sat, 19 Dec 2020 22:51:41 -0500 Subject: [PATCH] Replace calls to putenv with setenv (#99) * Use setenv instead of putenv * Replace sprintf with snprintf * unixfork.c: Stack allocate tempstring --- src/unixfork.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/unixfork.c b/src/unixfork.c index d7e398c..04c806f 100644 --- a/src/unixfork.c +++ b/src/unixfork.c @@ -144,11 +144,10 @@ int ForkUnixShell(int slot, char ltr, char numb, char *termtype, char *shellarg) /* set the LDESHELL variable so the underlying .cshrc can see it and configure the shell appropriately, though this may not be so important any more */ - putenv("LDESHELL=YES"); + setenv("LDESHELL", "YES", 1); if ((termtype[0] != 0) && (strlen(termtype) < 59)) { /* set the TERM environment var */ - sprintf(envstring, "TERM=%s", termtype); - putenv(envstring); + setenv("TERM", termtype, 1); } /* Start up csh */ argvec[0] = "csh"; @@ -269,23 +268,19 @@ int fork_Unix() { and put their numbers in the environment so parent can find them */ /* JDS - NB that sprintf doesn't always return a string! */ - char *tempstring; + char tempstring[30]; - tempstring = (char *)malloc(30); - sprintf(tempstring, "LDEPIPEIN=%d", UnixToLisp[0]); - putenv(tempstring); + snprintf(tempstring, sizeof(tempstring), "%d", UnixToLisp[0]); + setenv("LDEPIPEINE", tempstring, 1); - tempstring = (char *)malloc(30); - sprintf(tempstring, "LDEPIPEOUT=%d", LispToUnix[1]); - putenv(tempstring); + snprintf(tempstring, sizeof(tempstring), "%d", LispToUnix[1]); + setenv("LDEPIPEOUT", tempstring, 1); - tempstring = (char *)malloc(30); - sprintf(tempstring, "LDESTARTTIME=%ld", StartTime); - putenv(tempstring); + snprintf(tempstring, sizeof(tempstring), "%ld", StartTime); + setenv("LDESTARTTIME", tempstring, 1); - tempstring = (char *)malloc(30); - sprintf(tempstring, "LDEUNIXPID=%d", UnixPID); - putenv(tempstring); + snprintf(tempstring, sizeof(tempstring), "%d", UnixPID); + setenv("LDEUNIXPID", tempstring, 1); close(LispToUnix[0]); close(UnixToLisp[1]);