mirror of
https://github.com/Tha14/toxic.git
synced 2025-07-01 16:06:44 +02:00
another UB fix
This commit is contained in:
@ -234,18 +234,23 @@ int complete_line(ChatContext *ctx, const void *list, int n_items, int size)
|
||||
char tmp[MAX_STR_SIZE];
|
||||
snprintf(tmp, sizeof(tmp), "%s", ubuf);
|
||||
tmp[ctx->pos] = '\0';
|
||||
char *sub = strrchr(tmp, ' ');
|
||||
const char *s = strrchr(tmp, ' ');
|
||||
char *sub = malloc(strlen(ubuf) + 1);
|
||||
int n_endchrs = 1; /* 1 = append space to end of match, 2 = append ": " */
|
||||
|
||||
if (!sub++) {
|
||||
sub = tmp;
|
||||
if (!s) {
|
||||
strcpy(sub, tmp);
|
||||
|
||||
if (sub[0] != '/') /* make sure it's not a command */
|
||||
n_endchrs = 2;
|
||||
} else {
|
||||
strcpy(sub, &s[1]);
|
||||
}
|
||||
|
||||
if (string_is_empty(sub))
|
||||
if (string_is_empty(sub)) {
|
||||
free(sub);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int s_len = strlen(sub);
|
||||
const char *match;
|
||||
@ -260,6 +265,8 @@ int complete_line(ChatContext *ctx, const void *list, int n_items, int size)
|
||||
break;
|
||||
}
|
||||
|
||||
free(sub);
|
||||
|
||||
if (!is_match)
|
||||
return -1;
|
||||
|
||||
|
Reference in New Issue
Block a user