1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-12-23 20:13:24 +01:00

another UB fix

This commit is contained in:
Jfreegman 2014-07-16 15:55:04 -04:00
parent ce4f293574
commit 83f0720a39
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
3 changed files with 13 additions and 6 deletions

View File

@ -177,7 +177,7 @@ static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int p
uint16_t n_len = tox_get_self_name(m, (uint8_t *) selfnick); uint16_t n_len = tox_get_self_name(m, (uint8_t *) selfnick);
selfnick[n_len] = '\0'; selfnick[n_len] = '\0';
bool nick_match = strcasestr(action, selfnick); const char *nick_match = strcasestr(action, selfnick);
if (nick_match) { if (nick_match) {
alert_type = WINDOW_ALERT_0; alert_type = WINDOW_ALERT_0;

View File

@ -234,18 +234,23 @@ int complete_line(ChatContext *ctx, const void *list, int n_items, int size)
char tmp[MAX_STR_SIZE]; char tmp[MAX_STR_SIZE];
snprintf(tmp, sizeof(tmp), "%s", ubuf); snprintf(tmp, sizeof(tmp), "%s", ubuf);
tmp[ctx->pos] = '\0'; 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 ": " */ int n_endchrs = 1; /* 1 = append space to end of match, 2 = append ": " */
if (!sub++) { if (!s) {
sub = tmp; strcpy(sub, tmp);
if (sub[0] != '/') /* make sure it's not a command */ if (sub[0] != '/') /* make sure it's not a command */
n_endchrs = 2; n_endchrs = 2;
} else {
strcpy(sub, &s[1]);
} }
if (string_is_empty(sub)) if (string_is_empty(sub)) {
free(sub);
return -1; return -1;
}
int s_len = strlen(sub); int s_len = strlen(sub);
const char *match; const char *match;
@ -260,6 +265,8 @@ int complete_line(ChatContext *ctx, const void *list, int n_items, int size)
break; break;
} }
free(sub);
if (!is_match) if (!is_match)
return -1; return -1;