Skip to content

Commit

Permalink
Avoid potential ArgumentNullException
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Jul 18, 2022
1 parent 75d3644 commit fccf42d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/datacollector/DataCollectorMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ public void Run(string[]? args)
});

// Get server port and initialize communication.
int port = argsDictionary.TryGetValue(PortArgument, out var portValue) ? int.Parse(portValue!, CultureInfo.CurrentCulture) : 0;
int port = argsDictionary.TryGetValue(PortArgument, out var portValue)
&& int.TryParse(portValue, NumberStyles.Integer, CultureInfo.CurrentCulture, out var p)
? p
: 0;

if (port <= 0)
{
Expand Down

0 comments on commit fccf42d

Please sign in to comment.