Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Properly handle failures to convert widechar strings to multibyte #153

Merged
merged 1 commit into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ bool chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)

wstrsubst(ctx->line, L'¶', L'\n');

char line[MAX_STR_SIZE] = {0};
char line[MAX_STR_SIZE];

if (wcs_to_mbs_buf(line, ctx->line, MAX_STR_SIZE) == -1) {
memset(line, 0, sizeof(line));
Expand All @@ -1163,7 +1163,7 @@ bool chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
} else {
execute(ctx->history, self, m, line, CHAT_COMMAND_MODE);
}
} else {
} else if (line[0]) {
char selfname[TOX_MAX_NAME_LENGTH];
tox_self_get_name(m, (uint8_t *) selfname);

Expand All @@ -1175,6 +1175,8 @@ bool chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)

int id = line_info_add(self, timefrmt, selfname, NULL, OUT_MSG, 0, 0, "%s", line);
cqueue_add(ctx->cqueue, line, strlen(line), OUT_MSG, id);
} else {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Failed to parse message.");
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/conference.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,12 +951,14 @@ static bool conference_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
} else {
execute(ctx->history, self, m, line, CONFERENCE_COMMAND_MODE);
}
} else {
} else if (line[0]) {
Tox_Err_Conference_Send_Message err;

if (!tox_conference_send_message(m, self->num, TOX_MESSAGE_TYPE_NORMAL, (uint8_t *) line, strlen(line), &err)) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Failed to send message (error %d)", err);
}
} else {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Failed to parse message.");
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,14 @@ static bool prompt_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
add_line_to_hist(ctx);
wstrsubst(ctx->line, L'¶', L'\n');

char line[MAX_STR_SIZE] = {0};
char line[MAX_STR_SIZE];

if (wcs_to_mbs_buf(line, ctx->line, MAX_STR_SIZE) == -1) {
memset(line, 0, sizeof(line));
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Failed to parse message.");
} else {
line_info_add(self, NULL, NULL, NULL, PROMPT, 0, 0, "%s", line);
execute(ctx->history, self, m, line, GLOBAL_COMMAND_MODE);
}

line_info_add(self, NULL, NULL, NULL, PROMPT, 0, 0, "%s", line);
execute(ctx->history, self, m, line, GLOBAL_COMMAND_MODE);
}

wclear(ctx->linewin);
Expand Down