From 315ed474f2abe6e7b5a37cf1f0f3028384a8bc03 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 15 Jun 2008 11:22:52 +0000 Subject: [PATCH] fix crash in wxSetEnv(var, NULL) (#9585) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@54228 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/os2/utils.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/os2/utils.cpp b/src/os2/utils.cpp index 9313677cec..b821817d70 100644 --- a/src/os2/utils.cpp +++ b/src/os2/utils.cpp @@ -241,8 +241,17 @@ bool wxGetEnv(const wxString& var, wxString *value) bool wxSetEnv(const wxString& variable, const wxChar *value) { #if defined(HAVE_SETENV) - return setenv(variable.mb_str(), value ? wxString(value).mb_str() - : NULL, 1 /* overwrite */) == 0; + if ( !value ) + { +#ifdef HAVE_UNSETENV + return unsetenv(variable.mb_str()) == 0; +#else + value = _T(""); // mustn't pass NULL to setenv() +#endif + } + return setenv(variable.mb_str(), + wxString(value).mb_str(), + 1 /* overwrite */) == 0; #elif defined(HAVE_PUTENV) wxString s = variable; if ( value )