From 99e9c36a6927c2fd6547f1b79ce936a2403e1147 Mon Sep 17 00:00:00 2001 From: RogueException Date: Sun, 21 Aug 2016 11:07:32 -0300 Subject: [PATCH] Fixed nullrefs in command parsing --- src/Discord.Net.Commands/CommandParser.cs | 2 +- src/Discord.Net.Commands/Results/ParseResult.cs | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net.Commands/CommandParser.cs b/src/Discord.Net.Commands/CommandParser.cs index 30b72647e..d4f2404a3 100644 --- a/src/Discord.Net.Commands/CommandParser.cs +++ b/src/Discord.Net.Commands/CommandParser.cs @@ -156,7 +156,7 @@ namespace Discord.Commands return ParseResult.FromError(CommandError.ParseFailed, "A quoted parameter is incomplete"); //Add missing optionals - for (int i = paramList.Count; i < command.Parameters.Count; i++) + for (int i = argList.Count; i < command.Parameters.Count; i++) { var param = command.Parameters[i]; if (!param.IsOptional) diff --git a/src/Discord.Net.Commands/Results/ParseResult.cs b/src/Discord.Net.Commands/Results/ParseResult.cs index 22fdc4259..5bc0cb80f 100644 --- a/src/Discord.Net.Commands/Results/ParseResult.cs +++ b/src/Discord.Net.Commands/Results/ParseResult.cs @@ -41,9 +41,13 @@ namespace Discord.Commands var argList = new TypeReaderResult[argValues.Count]; for (int i = 0; i < argValues.Count; i++) argList[i] = TypeReaderResult.FromSuccess(argValues[i]); - var paramList = new TypeReaderResult[paramValues.Count]; - for (int i = 0; i < paramValues.Count; i++) - paramList[i] = TypeReaderResult.FromSuccess(paramValues[i]); + TypeReaderResult[] paramList = null; + if (paramValues != null) + { + paramList = new TypeReaderResult[paramValues.Count]; + for (int i = 0; i < paramValues.Count; i++) + paramList[i] = TypeReaderResult.FromSuccess(paramValues[i]); + } return new ParseResult(argList, paramList, null, null); }