1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-07-01 03:36:45 +02:00

more error handling

This commit is contained in:
Jfreegman
2013-09-11 18:07:26 -04:00
parent f004a4ba82
commit 052f9f9936
3 changed files with 50 additions and 19 deletions

View File

@ -142,12 +142,22 @@ static char *wcs_to_char(wchar_t *string)
if (len != (size_t) -1) {
len++;
ret = malloc(len);
wcstombs(ret, string, len);
if (ret != NULL)
wcstombs(ret, string, len);
} else {
ret = malloc(2);
ret[0] = ' ';
ret[1] = '\0';
if (ret != NULL) {
ret[0] = ' ';
ret[1] = '\0';
}
}
if (ret == NULL) {
fprintf(stderr, "malloc() failed. Aborting...\n");
endwin();
exit(EXIT_FAILURE);
}
return ret;
}
@ -533,8 +543,16 @@ ToxWindow new_chat(Tox *m, ToxWindow *prompt, int friendnum)
ChatContext *x = calloc(1, sizeof(ChatContext));
StatusBar *s = calloc(1, sizeof(StatusBar));
ret.x = x;
ret.s = s;
if (s != NULL && x != NULL) {
ret.x = x;
ret.s = s;
} else {
fprintf(stderr, "calloc() failed. Aborting...\n");
endwin();
exit(EXIT_FAILURE);
}
ret.prompt = prompt;
ret.friendnum = friendnum;