shell: fix crash for commands without a long description

This commit is contained in:
Lephenixnoir 2023-09-03 19:03:48 +02:00
parent 47764a61eb
commit 6406f05eb2
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
1 changed files with 8 additions and 6 deletions

View File

@ -27,12 +27,14 @@ ShellCommand::ShellCommand(std::string _name, ShellFunction _function,
function {_function},
completer {_completer}, short_description {_shortd}
{
/* Left trim */
_longd.erase(0, _longd.find_first_not_of("\n"));
/* Right trim */
int r = _longd.size();
while(r > 0 && _longd[--r] == '\n') {}
_longd.erase(r + 1, _longd.size());
if(_longd.size()) {
/* Left trim */
_longd.erase(0, _longd.find_first_not_of("\n"));
/* Right trim */
int r = _longd.size();
while(r > 0 && _longd[--r] == '\n') {}
_longd.erase(r + 1, _longd.size());
}
this->long_description = _longd;
commands[_name] = this;