Skip to content

Commit

Permalink
[msbuild] Avoid possible NullReferenceException in ScnToolTaskBase. F…
Browse files Browse the repository at this point in the history
…ixes #4039 (#5006)

`EnvironmentVariables` can be null (not empty) and cause the NRE in the
attached test case.

It's not clear that the extra logic is needed if we were using `xcrun`.
There's an enhancement for this #4634

reference: #4039
  • Loading branch information
spouliot authored Oct 18, 2018
1 parent 5ad55d6 commit 99641c7
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions msbuild/Xamarin.MacDev.Tasks.Core/Tasks/ScnToolTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,21 @@ void SetEnvironmentVariable (string variableName, string value)
var envVariables = EnvironmentVariables;
var index = -1;

for (int i = 0; i < envVariables.Length; i++) {
if (envVariables [i].StartsWith (variableName + "=", StringComparison.Ordinal)) {
index = i;
break;
if (envVariables == null) {
envVariables = new string [1];
index = 0;
} else {
for (int i = 0; i < envVariables.Length; i++) {
if (envVariables [i].StartsWith (variableName + "=", StringComparison.Ordinal)) {
index = i;
break;
}
}
}

if (index < 0) {
Array.Resize<string> (ref envVariables, envVariables.Length + 1);
index = envVariables.Length - 1;
if (index < 0) {
Array.Resize<string> (ref envVariables, envVariables.Length + 1);
index = envVariables.Length - 1;
}
}

envVariables [index] = string.Format ("{0}={1}", variableName, value);
Expand Down

1 comment on commit 99641c7

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jenkins job (on internal Jenkins) succeeded

Build succeeded
API Diff (from stable)
ℹ️ API Diff (from PR only) (please review changes)
Generator Diff (no change)
Test run succeeded

Please sign in to comment.