1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-07-01 20:07:46 +02:00

Merge pull request #240 from s3erios/master

Fix some 'clang --analyze' warnings
This commit is contained in:
JFreegman 2014-09-05 13:16:43 -04:00
commit 6876df4a45
2 changed files with 12 additions and 19 deletions

View File

@ -130,11 +130,12 @@ static int save_blocklist(char *path)
exit_toxic_err("Failed in save_blocklist", FATALERR_MEMORY); exit_toxic_err("Failed in save_blocklist", FATALERR_MEMORY);
int i; int i;
int ret = -1;
int count = 0; int count = 0;
for (i = 0; i < Blocked.max_idx; ++i) { for (i = 0; i < Blocked.max_idx; ++i) {
if (count > Blocked.num_blocked) if (count > Blocked.num_blocked)
return -1; goto on_error;
if (Blocked.list[i].active) { if (Blocked.list[i].active) {
BlockedFriend tmp; BlockedFriend tmp;
@ -155,17 +156,14 @@ static int save_blocklist(char *path)
FILE *fp = fopen(path, "wb"); FILE *fp = fopen(path, "wb");
if (fp == NULL) { if (fp == NULL)
free(data); goto on_error;
return -1;
}
int ret = 0; if (fwrite(data, len, 1, fp) == 1)
ret = 0;
if (fwrite(data, len, 1, fp) != 1)
ret = -1;
fclose(fp); fclose(fp);
on_error:
free(data); free(data);
return ret; return ret;
} }

View File

@ -107,15 +107,6 @@ static void line_info_root_fwd(struct history *hst)
hst->line_root = tmp; hst->line_root = tmp;
} }
/* adds a line_info line to queue */
static void line_info_add_queue(struct history *hst, struct line_info *line)
{
if (hst->queue_sz >= MAX_QUEUE)
return;
hst->queue[hst->queue_sz++] = line;
}
/* returns ptr to queue item 0 and removes it from queue */ /* returns ptr to queue item 0 and removes it from queue */
static struct line_info *line_info_ret_queue(struct history *hst) static struct line_info *line_info_ret_queue(struct history *hst)
{ {
@ -140,6 +131,10 @@ void line_info_add(ToxWindow *self, char *tmstmp, char *name1, char *name2, uint
uint8_t colour, const char *msg, ...) uint8_t colour, const char *msg, ...)
{ {
struct history *hst = self->chatwin->hst; struct history *hst = self->chatwin->hst;
if (hst->queue_sz >= MAX_QUEUE)
return;
struct line_info *new_line = calloc(1, sizeof(struct line_info)); struct line_info *new_line = calloc(1, sizeof(struct line_info));
if (new_line == NULL) if (new_line == NULL)
@ -205,7 +200,7 @@ void line_info_add(ToxWindow *self, char *tmstmp, char *name1, char *name2, uint
new_line->bold = bold; new_line->bold = bold;
new_line->colour = colour; new_line->colour = colour;
line_info_add_queue(hst, new_line); hst->queue[hst->queue_sz++] = new_line;
} }
/* adds a single queue item to hst if possible. only called once per call to line_info_print() */ /* adds a single queue item to hst if possible. only called once per call to line_info_print() */