[FL-1620] Cli command list crash fix. Correct name validation in scripts. (#613)

* Scripts: fix incorrect name validation regexp.
* Cli: fix command list iteration.
This commit is contained in:
あく 2021-07-29 18:27:06 +03:00 committed by GitHub
parent 12113b480d
commit 4c85bfedca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 16 deletions

View File

@ -94,23 +94,30 @@ void cli_command_help(Cli* cli, string_t args, void* context) {
(void)args; (void)args;
printf("Commands we have:"); printf("Commands we have:");
// Get the middle element // Command count
CliCommandTree_it_t it_mid; const size_t commands_count = CliCommandTree_size(cli->commands);
uint8_t cmd_num = CliCommandTree_size(cli->commands); const size_t commands_count_mid = commands_count / 2 + commands_count % 2;
uint8_t i = cmd_num / 2 + cmd_num % 2;
for(CliCommandTree_it(it_mid, cli->commands); i; --i, CliCommandTree_next(it_mid))
;
// Use 2 iterators from start and middle to show 2 columns // Use 2 iterators from start and middle to show 2 columns
CliCommandTree_it_t it_i; CliCommandTree_it_t it_left;
CliCommandTree_it_t it_j; CliCommandTree_it(it_left, cli->commands);
for(CliCommandTree_it(it_i, cli->commands), CliCommandTree_it_set(it_j, it_mid); CliCommandTree_it_t it_right;
!CliCommandTree_it_equal_p(it_i, it_mid); CliCommandTree_it(it_right, cli->commands);
CliCommandTree_next(it_i), CliCommandTree_next(it_j)) { for(size_t i = 0; i < commands_count_mid; i++) CliCommandTree_next(it_right);
CliCommandTree_itref_t* ref = CliCommandTree_ref(it_i);
// Iterate throw tree
for(size_t i = 0; i < commands_count_mid; i++) {
printf("\r\n"); printf("\r\n");
printf("%-30s", string_get_cstr(ref->key_ptr[0])); // Left Column
ref = CliCommandTree_ref(it_j); if(!CliCommandTree_end_p(it_left)) {
printf(string_get_cstr(ref->key_ptr[0])); printf("%-30s", string_get_cstr(*CliCommandTree_ref(it_left)->key_ptr));
CliCommandTree_next(it_left);
}
// Right Column
if(!CliCommandTree_end_p(it_right)) {
printf(string_get_cstr(*CliCommandTree_ref(it_right)->key_ptr));
CliCommandTree_next(it_right);
}
}; };
if(string_size(args) > 0) { if(string_size(args) > 0) {

View File

@ -89,7 +89,7 @@ class Main:
if len(self.args.name) > 8: if len(self.args.name) > 8:
self.parser.error("Name is too long. Max 8 symbols.") self.parser.error("Name is too long. Max 8 symbols.")
if re.match(r"[a-zA-Z0-9]+", self.args.name) is None: if re.match(r"^[a-zA-Z0-9.]+$", self.args.name) is None:
self.parser.error( self.parser.error(
"Name contains incorrect symbols. Only a-zA-Z0-9 allowed." "Name contains incorrect symbols. Only a-zA-Z0-9 allowed."
) )