From fccf42d4d528e9850a2138a91151be9f471cc673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 18 Jul 2022 16:56:57 +0200 Subject: [PATCH] Avoid potential ArgumentNullException --- src/datacollector/DataCollectorMain.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/datacollector/DataCollectorMain.cs b/src/datacollector/DataCollectorMain.cs index 4fc0c28747..89b77bd4b5 100644 --- a/src/datacollector/DataCollectorMain.cs +++ b/src/datacollector/DataCollectorMain.cs @@ -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) {