mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 21:33:02 +01:00
more error handling
This commit is contained in:
parent
f004a4ba82
commit
052f9f9936
28
src/chat.c
28
src/chat.c
@ -142,12 +142,22 @@ static char *wcs_to_char(wchar_t *string)
|
|||||||
if (len != (size_t) -1) {
|
if (len != (size_t) -1) {
|
||||||
len++;
|
len++;
|
||||||
ret = malloc(len);
|
ret = malloc(len);
|
||||||
wcstombs(ret, string, len);
|
if (ret != NULL)
|
||||||
|
wcstombs(ret, string, len);
|
||||||
} else {
|
} else {
|
||||||
ret = malloc(2);
|
ret = malloc(2);
|
||||||
ret[0] = ' ';
|
if (ret != NULL) {
|
||||||
ret[1] = '\0';
|
ret[0] = ' ';
|
||||||
|
ret[1] = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ret == NULL) {
|
||||||
|
fprintf(stderr, "malloc() failed. Aborting...\n");
|
||||||
|
endwin();
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -533,8 +543,16 @@ ToxWindow new_chat(Tox *m, ToxWindow *prompt, int friendnum)
|
|||||||
|
|
||||||
ChatContext *x = calloc(1, sizeof(ChatContext));
|
ChatContext *x = calloc(1, sizeof(ChatContext));
|
||||||
StatusBar *s = calloc(1, sizeof(StatusBar));
|
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.prompt = prompt;
|
||||||
ret.friendnum = friendnum;
|
ret.friendnum = friendnum;
|
||||||
|
25
src/main.c
25
src/main.c
@ -317,14 +317,14 @@ static void load_data(Tox *m, char *path)
|
|||||||
buf = malloc(len);
|
buf = malloc(len);
|
||||||
|
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
fprintf(stderr, "malloc() failed.\n");
|
fprintf(stderr, "malloc() failed. Aborting...\n");
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
endwin();
|
endwin();
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fread(buf, len, 1, fd) != 1) {
|
if (fread(buf, len, 1, fd) != 1) {
|
||||||
fprintf(stderr, "fread() failed.\n");
|
fprintf(stderr, "fread() failed. Aborting...\n");
|
||||||
free(buf);
|
free(buf);
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
endwin();
|
endwin();
|
||||||
@ -357,13 +357,9 @@ static void load_data(Tox *m, char *path)
|
|||||||
void exit_toxic(Tox *m)
|
void exit_toxic(Tox *m)
|
||||||
{
|
{
|
||||||
store_data(m, DATA_FILE);
|
store_data(m, DATA_FILE);
|
||||||
|
free(DATA_FILE);
|
||||||
if (DATA_FILE != NULL)
|
free(SRVLIST_FILE);
|
||||||
free(DATA_FILE);
|
free(prompt->s);
|
||||||
|
|
||||||
if (SRVLIST_FILE != NULL)
|
|
||||||
free(SRVLIST_FILE);
|
|
||||||
|
|
||||||
tox_kill(m);
|
tox_kill(m);
|
||||||
endwin();
|
endwin();
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
@ -401,17 +397,20 @@ int main(int argc, char *argv[])
|
|||||||
SRVLIST_FILE = strdup(PACKAGE_DATADIR "/DHTservers");
|
SRVLIST_FILE = strdup(PACKAGE_DATADIR "/DHTservers");
|
||||||
} else {
|
} else {
|
||||||
DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1);
|
DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1);
|
||||||
if (DATA_FILE != NULL) {
|
SRVLIST_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("DHTservers") + 1);
|
||||||
|
|
||||||
|
if (DATA_FILE != NULL && SRVLIST_FILE != NULL) {
|
||||||
strcpy(DATA_FILE, user_config_dir);
|
strcpy(DATA_FILE, user_config_dir);
|
||||||
strcat(DATA_FILE, CONFIGDIR);
|
strcat(DATA_FILE, CONFIGDIR);
|
||||||
strcat(DATA_FILE, "data");
|
strcat(DATA_FILE, "data");
|
||||||
}
|
|
||||||
|
|
||||||
SRVLIST_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("DHTservers") + 1);
|
|
||||||
if (SRVLIST_FILE != NULL) {
|
|
||||||
strcpy(SRVLIST_FILE, user_config_dir);
|
strcpy(SRVLIST_FILE, user_config_dir);
|
||||||
strcat(SRVLIST_FILE, CONFIGDIR);
|
strcat(SRVLIST_FILE, CONFIGDIR);
|
||||||
strcat(SRVLIST_FILE, "DHTservers");
|
strcat(SRVLIST_FILE, "DHTservers");
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "malloc() failed. Aborting...\n");
|
||||||
|
endwin();
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
src/prompt.c
16
src/prompt.c
@ -113,6 +113,13 @@ unsigned char *hex_string_to_bin(char hex_string[])
|
|||||||
{
|
{
|
||||||
size_t len = strlen(hex_string);
|
size_t len = strlen(hex_string);
|
||||||
unsigned char *val = malloc(len);
|
unsigned char *val = malloc(len);
|
||||||
|
|
||||||
|
if (val == NULL) {
|
||||||
|
fprintf(stderr, "malloc() failed. Aborting...\n");
|
||||||
|
endwin();
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
char *pos = hex_string;
|
char *pos = hex_string;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -688,7 +695,14 @@ ToxWindow new_prompt()
|
|||||||
strcpy(ret.name, "prompt");
|
strcpy(ret.name, "prompt");
|
||||||
|
|
||||||
StatusBar *s = calloc(1, sizeof(StatusBar));
|
StatusBar *s = calloc(1, sizeof(StatusBar));
|
||||||
ret.s = s;
|
|
||||||
|
if (s != NULL)
|
||||||
|
ret.s = s;
|
||||||
|
else {
|
||||||
|
fprintf(stderr, "calloc() failed. Aborting...\n");
|
||||||
|
endwin();
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user