From 0a610a5810dbe9251e64b721f791d3a1255b2821 Mon Sep 17 00:00:00 2001 From: Tennessee Carmel-Veilleux Date: Thu, 14 Apr 2022 08:09:59 -0400 Subject: [PATCH] Remove unhelpful ParseArgs help text validation - Help text validation when CHIP_CONFIG_ENABLE_ARG_PARSER_VALIDITY_CHECKS are enabled are both unhelpful and unsafe. Unhelpful because such failures are unlikely to get better code delivered, and unsafe because the algorithms used make use of sketchy tricky code with negative indexing that was shown to sometimes fail on ARM builds. This PR removes the help content checks Fixes #17323 --- src/lib/support/CHIPArgParser.cpp | 46 ------------------------------- 1 file changed, 46 deletions(-) diff --git a/src/lib/support/CHIPArgParser.cpp b/src/lib/support/CHIPArgParser.cpp index 91b6dfefb8ab74..d762da772d61f1 100644 --- a/src/lib/support/CHIPArgParser.cpp +++ b/src/lib/support/CHIPArgParser.cpp @@ -77,8 +77,6 @@ static void PutStringWithNewLine(FILE * s, const char * str); static void PutStringWithBlankLine(FILE * s, const char * str); #if CHIP_CONFIG_ENABLE_ARG_PARSER_VALIDITY_CHECKS static bool SanityCheckOptions(OptionSet * optSets[]); -static bool HelpTextContainsLongOption(const char * optName, const char * helpText); -static bool HelpTextContainsShortOption(char optChar, const char * helpText); #endif // CHIP_CONFIG_ENABLE_ARG_PARSER_VALIDITY_CHECKS static inline bool IsShortOptionChar(int ch) @@ -1511,53 +1509,9 @@ static bool SanityCheckOptions(OptionSet * optSets[]) } } - // Fail if the option help texts do not contain a description for each option, including both - // the option's long and short forms. - for (OptionSet ** optSetP = optSets; *optSetP != nullptr; optSetP++) - for (OptionDef * optionDef = (*optSetP)->OptionDefs; optionDef->Name != nullptr; optionDef++) - { - if (!HelpTextContainsLongOption(optionDef->Name, (*optSetP)->OptionHelp)) - { - PrintArgError("INTERNAL ERROR: No help text defined for option: --%s\n", optionDef->Name); - res = false; - } - - if (IsShortOptionChar(optionDef->Id) && - !HelpTextContainsShortOption(static_cast(optionDef->Id), (*optSetP)->OptionHelp)) - { - PrintArgError("INTERNAL ERROR: No help text defined for option: -%c\n", optionDef->Id); - res = false; - } - } - return res; } -static bool HelpTextContainsLongOption(const char * optName, const char * helpText) -{ - size_t nameLen = strlen(optName); - - for (const char * p = helpText; (p = strstr(p, optName)) != nullptr; p += nameLen) - if ((p - helpText) >= 2 && p[-1] == '-' && p[-2] == '-' && !isalnum(p[nameLen]) && p[nameLen] != '-') - return true; - - return false; -} - -static bool HelpTextContainsShortOption(char optChar, const char * helpText) -{ - char optStr[3]; - optStr[0] = '-'; - optStr[1] = optChar; - optStr[2] = 0; - - for (const char * p = helpText; (p = strstr(p, optStr)) != nullptr; p += 2) - if ((p == helpText || (!isalnum(p[-1]) && p[-1] != '-')) && !isalnum(p[2]) && p[2] != '-') - return true; - - return false; -} - #endif // CHIP_CONFIG_ENABLE_ARG_PARSER_VALIDITY_CHECKS } // namespace ArgParser