1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 14:12:10 +02:00

ProcessFactory.java : envpToEnvMap() consider null envp (#195)

This commit is contained in:
徐持恒 Xu Chiheng 2022-12-07 05:05:28 +08:00 committed by GitHub
parent ac64d4aedc
commit 352630b8ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -62,9 +62,17 @@ public class ProcessFactory {
return environment; return environment;
} }
private static TreeMap<String, String> envpToEnvMap(String[] envp) { private static TreeMap<String, String> getDefaultEnvironment() {
TreeMap<String, String> environment = newEmptyEnvironment(); TreeMap<String, String> environment = newEmptyEnvironment();
Map<String, String> env = new ProcessBuilder().environment();
environment.putAll(env);
return environment;
}
private static TreeMap<String, String> envpToEnvMap(String[] envp) {
TreeMap<String, String> environment;
if (envp != null) { if (envp != null) {
environment = newEmptyEnvironment();
for (String envstring : envp) { for (String envstring : envp) {
int eqlsign = envstring.indexOf('='); int eqlsign = envstring.indexOf('=');
if (eqlsign != -1) { if (eqlsign != -1) {
@ -73,17 +81,12 @@ public class ProcessFactory {
// Silently ignore envstrings lacking the required `='. // Silently ignore envstrings lacking the required `='.
} }
} }
} else {
environment = getDefaultEnvironment();
} }
return environment; return environment;
} }
private static TreeMap<String, String> getDefaultEnvironment() {
TreeMap<String, String> environment = newEmptyEnvironment();
Map<String, String> env = new ProcessBuilder().environment();
environment.putAll(env);
return environment;
}
private static void appendEnvMapComparison(StringBuilder sb, TreeMap<String, String> environmentA, private static void appendEnvMapComparison(StringBuilder sb, TreeMap<String, String> environmentA,
TreeMap<String, String> environmentB) { TreeMap<String, String> environmentB) {
TreeMap<String, String> environmentC = newEmptyEnvironment(); TreeMap<String, String> environmentC = newEmptyEnvironment();