[m-rev.] diff: get system building under cygwin and mingw

Julien Fischer juliensf at csse.unimelb.edu.au
Tue Nov 28 19:42:42 AEDT 2006


On Tue, 28 Nov 2006, Peter Ross wrote:

> Index: runtime/mercury_runtime_util.c
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/runtime/mercury_runtime_util.c,v
> retrieving revision 1.4
> diff -U5 -r1.4 mercury_runtime_util.c
> --- runtime/mercury_runtime_util.c	14 Nov 2006 00:15:41 -0000	1.4
> +++ runtime/mercury_runtime_util.c	28 Nov 2006 06:47:03 -0000
> @@ -83,5 +83,38 @@
>         fprintf(stderr, "Mercury runtime: error in call to atexit: %s\n",
>             strerror(errno));
>         exit(EXIT_FAILURE);
>     }
> }
> +
> +#if ! defined(MR_HAVE_PUTENV) && defined(MR_HAVE__PUTENV)
> +  #define putenv _putenv
> +#endif
> +
> +int
> +MR_setenv(const char *name, const char *value, int overwrite)
> +{
> +#if defined(MR_HAVE_SETENV)
> +    return setenv(name, value, overwrite);
> +#elif defined(MR_HAVE_PUTENV) || defined(MR_HAVE__PUTENV)
> +    char *env;
> +    int length;
> +
> +    if (!overwrite && getenv(name) != NULL) {
> +        return 0;
> +    }
> +
> +    length = strlen(name) + strlen(value) + 2;
> +    env = MR_NEW_ARRAY(char, length);
> +
> +    env[0] = '\0';
> +    strcat(env, name);
> +    strcat(env, "=");
> +    strcat(env, value);
> +
> +    MR_free(env);
> +
> +    return putenv(env);

You're using that memory after you've freed it.  Rewrite as:

 	int putevn_result;

 	...

 	putenv_result = putenv(env);
 	MR_free(env);
 	return res;

Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list