1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-22 22:03:02 +01:00

Fix autocomplete bug

Formatting was messed up due to not accounting for null byte in directory list
This commit is contained in:
jfreegman 2018-02-20 20:54:26 -05:00
parent b14d983a8c
commit 5cd196a769
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
2 changed files with 12 additions and 10 deletions

View File

@ -38,16 +38,18 @@
#include "execute.h" #include "execute.h"
#include "configdir.h" #include "configdir.h"
static void print_matches(ToxWindow *self, Tox *m, const void *list, int n_items, int size) static void print_matches(ToxWindow *self, Tox *m, const void *list, size_t n_items, size_t size)
{ {
if (m) if (m) {
execute(self->chatwin->history, self, m, "/clear", GLOBAL_COMMAND_MODE); execute(self->chatwin->history, self, m, "/clear", GLOBAL_COMMAND_MODE);
}
const char *L = (char *) list; const char *L = (char *) list;
int i; int i;
for (i = 0; i < n_items; ++i) for (i = 0; i < n_items; ++i) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", &L[i * size]); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", &L[i * size]);
}
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, ""); /* formatting */ line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, ""); /* formatting */
} }
@ -91,7 +93,7 @@ static size_t get_str_match(ToxWindow *self, char *match, size_t match_sz, char
in the list, and size is the size of each item in the list. in the list, and size is the size of each item in the list.
Returns the difference between the old len and new len of line on success, -1 if error */ Returns the difference between the old len and new len of line on success, -1 if error */
int complete_line(ToxWindow *self, const void *list, int n_items, int size) int complete_line(ToxWindow *self, const void *list, size_t n_items, size_t size)
{ {
ChatContext *ctx = self->chatwin; ChatContext *ctx = self->chatwin;
@ -148,7 +150,7 @@ int complete_line(ToxWindow *self, const void *list, int n_items, int size)
} }
int s_len = strlen(sub); int s_len = strlen(sub);
int n_matches = 0; size_t n_matches = 0;
char matches[n_items][MAX_STR_SIZE]; char matches[n_items][MAX_STR_SIZE];
int i = 0; int i = 0;
@ -287,7 +289,7 @@ int dir_match(ToxWindow *self, Tox *m, const wchar_t *line, const wchar_t *cmd)
if (dp == NULL) if (dp == NULL)
return -1; return -1;
char dirnames[MAX_DIRS][NAME_MAX + 1]; char dirnames[MAX_DIRS][NAME_MAX+1];
struct dirent *entry; struct dirent *entry;
int dircount = 0; int dircount = 0;
@ -305,9 +307,9 @@ int dir_match(ToxWindow *self, Tox *m, const wchar_t *line, const wchar_t *cmd)
return -1; return -1;
if (dircount > 1) { if (dircount > 1) {
qsort(dirnames, dircount, NAME_MAX, qsort_strcasecmp_hlpr); qsort(dirnames, dircount, NAME_MAX + 1, qsort_strcasecmp_hlpr);
print_matches(self, m, dirnames, dircount, NAME_MAX); print_matches(self, m, dirnames, dircount, NAME_MAX + 1);
} }
return complete_line(self, dirnames, dircount, NAME_MAX); return complete_line(self, dirnames, dircount, NAME_MAX + 1);
} }

View File

@ -31,7 +31,7 @@
in the list, and size is the size of each item in the list. in the list, and size is the size of each item in the list.
Returns the difference between the old len and new len of line on success, -1 if error */ Returns the difference between the old len and new len of line on success, -1 if error */
int complete_line(ToxWindow *self, const void *list, int n_items, int size); int complete_line(ToxWindow *self, const void *list, size_t n_items, size_t size);
/* attempts to match /command "<incomplete-dir>" line to matching directories. /* attempts to match /command "<incomplete-dir>" line to matching directories.