Ver Fonte

Don't create the SDL environment in SDL_setenv_unsafe()

We might be setting an environment variable along with other application code setting environment variables (like code in SteamAPI_InitEx()) before initializing SDL.
Sam Lantinga há 2 meses atrás
pai
commit
d780fa144a
1 ficheiros alterados com 24 adições e 8 exclusões
  1. 24 8
      src/stdlib/SDL_getenv.c

+ 24 - 8
src/stdlib/SDL_getenv.c

@@ -337,7 +337,9 @@ int SDL_setenv_unsafe(const char *name, const char *value, int overwrite)
         return -1;
     }
 
-    SDL_SetEnvironmentVariable(SDL_GetEnvironment(), name, value, (overwrite != 0));
+    if (SDL_environment) {
+        SDL_SetEnvironmentVariable(SDL_environment, name, value, (overwrite != 0));
+    }
 
     return setenv(name, value, overwrite);
 }
@@ -352,7 +354,9 @@ int SDL_setenv_unsafe(const char *name, const char *value, int overwrite)
         return -1;
     }
 
-    SDL_SetEnvironmentVariable(SDL_GetEnvironment(), name, value, (overwrite != 0));
+    if (SDL_environment) {
+        SDL_SetEnvironmentVariable(SDL_environment, name, value, (overwrite != 0));
+    }
 
     if (getenv(name) != NULL) {
         if (!overwrite) {
@@ -376,7 +380,9 @@ int SDL_setenv_unsafe(const char *name, const char *value, int overwrite)
         return -1;
     }
 
-    SDL_SetEnvironmentVariable(SDL_GetEnvironment(), name, value, (overwrite != 0));
+    if (SDL_environment) {
+        SDL_SetEnvironmentVariable(SDL_environment, name, value, (overwrite != 0));
+    }
 
     if (!overwrite) {
         if (GetEnvironmentVariableA(name, NULL, 0) > 0) {
@@ -407,7 +413,9 @@ int SDL_setenv_unsafe(const char *name, const char *value, int overwrite)
         return 0;
     }
 
-    SDL_SetEnvironmentVariable(SDL_GetEnvironment(), name, value, (overwrite != 0));
+    if (SDL_environment) {
+        SDL_SetEnvironmentVariable(SDL_environment, name, value, (overwrite != 0));
+    }
 
     // Allocate memory for the variable
     len = SDL_strlen(name) + SDL_strlen(value) + 2;
@@ -462,7 +470,9 @@ int SDL_unsetenv_unsafe(const char *name)
         return -1;
     }
 
-    SDL_UnsetEnvironmentVariable(SDL_GetEnvironment(), name);
+    if (SDL_environment) {
+        SDL_UnsetEnvironmentVariable(SDL_environment, name);
+    }
 
     return unsetenv(name);
 }
@@ -475,7 +485,9 @@ int SDL_unsetenv_unsafe(const char *name)
         return -1;
     }
 
-    SDL_UnsetEnvironmentVariable(SDL_GetEnvironment(), name);
+    if (SDL_environment) {
+        SDL_UnsetEnvironmentVariable(SDL_environment, name);
+    }
 
     // Hope this environment uses the non-standard extension of removing the environment variable if it has no '='
     return putenv(name);
@@ -489,7 +501,9 @@ int SDL_unsetenv_unsafe(const char *name)
         return -1;
     }
 
-    SDL_UnsetEnvironmentVariable(SDL_GetEnvironment(), name);
+    if (SDL_environment) {
+        SDL_UnsetEnvironmentVariable(SDL_environment, name);
+    }
 
     if (!SetEnvironmentVariableA(name, NULL)) {
         return -1;
@@ -506,7 +520,9 @@ int SDL_unsetenv_unsafe(const char *name)
         return -1;
     }
 
-    SDL_UnsetEnvironmentVariable(SDL_GetEnvironment(), name);
+    if (SDL_environment) {
+        SDL_UnsetEnvironmentVariable(SDL_environment, name);
+    }
 
     if (environ) {
         len = SDL_strlen(name);