command/all: use class StaticVector

This commit is contained in:
Max Kellermann 2022-08-09 12:44:09 +02:00
parent a12b004fa4
commit d0909adf6b

View File

@ -42,6 +42,7 @@
#include "client/Client.hxx" #include "client/Client.hxx"
#include "client/Response.hxx" #include "client/Response.hxx"
#include "util/Tokenizer.hxx" #include "util/Tokenizer.hxx"
#include "util/StaticVector.hxx"
#include "util/StringAPI.hxx" #include "util/StringAPI.hxx"
#ifdef ENABLE_SQLITE #ifdef ENABLE_SQLITE
@ -402,14 +403,13 @@ command_process(Client &client, unsigned num, char *line) noexcept
return CommandResult::FINISH; return CommandResult::FINISH;
} }
char *argv[COMMAND_ARGV_MAX];
try { try {
/* now parse the arguments (quoted or unquoted) */ /* now parse the arguments (quoted or unquoted) */
std::size_t n_args = 0; StaticVector<const char *, COMMAND_ARGV_MAX> argv;
while (true) { while (true) {
if (n_args == COMMAND_ARGV_MAX) { if (argv.full()) {
r.Error(ACK_ERROR_ARG, "Too many arguments"); r.Error(ACK_ERROR_ARG, "Too many arguments");
return CommandResult::ERROR; return CommandResult::ERROR;
} }
@ -418,10 +418,10 @@ command_process(Client &client, unsigned num, char *line) noexcept
if (a == nullptr) if (a == nullptr)
break; break;
argv[n_args++] = a; argv.push_back(a);
} }
Request args{{argv, n_args}}; const Request args{argv};
/* look up and invoke the command handler */ /* look up and invoke the command handler */