aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2018-10-30 17:56:38 +0100
committerThomas White <taw@bitwiz.me.uk>2018-10-30 17:56:38 +0100
commit19f20ab06476f93977d1c7130b76f7c31d198936 (patch)
tree5410b960ab5b00d043a0d828299116baf38d0eeb
parent6171bc9d7f86ea0ac1c6abd4a213850fa4f81300 (diff)
Fix errors reported by static analyser
-rw-r--r--src/frame.c4
-rw-r--r--src/narrative_window.c10
-rw-r--r--src/sc_interp.c40
-rw-r--r--src/sc_parse.c35
-rw-r--r--src/stylesheet.c2
5 files changed, 74 insertions, 17 deletions
diff --git a/src/frame.c b/src/frame.c
index 2926d4e..cf6bd7f 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -698,7 +698,7 @@ void ensure_run(struct frame *fr, struct edit_pos cpos)
int find_cursor(struct frame *fr, double x, double y, struct edit_pos *pos)
{
- double pad = fr->pad_t;
+ double pad;
int i;
if ( fr == NULL ) {
@@ -706,6 +706,8 @@ int find_cursor(struct frame *fr, double x, double y, struct edit_pos *pos)
return 1;
}
+ pad = fr->pad_t;
+
for ( i=0; i<fr->n_paras; i++ ) {
double npos = pad + paragraph_height(fr->paras[i]);
if ( npos > y ) {
diff --git a/src/narrative_window.c b/src/narrative_window.c
index 7f3690e..3f936e0 100644
--- a/src/narrative_window.c
+++ b/src/narrative_window.c
@@ -732,10 +732,16 @@ GActionEntry nw_entries[] = {
void update_titlebar(NarrativeWindow *nw)
{
char *title;
+ char *title_new;
title = get_titlebar_string(nw->p);
- title = realloc(title, strlen(title)+16);
- if ( title == NULL ) return;
+ title_new = realloc(title, strlen(title)+16);
+ if ( title_new == NULL ) {
+ free(title);
+ return;
+ } else {
+ title = title_new;
+ }
strcat(title, " - Colloquium");
if ( !nw->p->saved ) {
diff --git a/src/sc_interp.c b/src/sc_interp.c
index 7bbfeeb..f2f604b 100644
--- a/src/sc_interp.c
+++ b/src/sc_interp.c
@@ -105,19 +105,44 @@ SCCallbackList *sc_callback_list_new()
if ( cbl == NULL ) return NULL;
cbl->names = calloc(8, sizeof(char *));
- if ( cbl->names == NULL ) return NULL;
+ if ( cbl->names == NULL ) {
+ free(cbl);
+ return NULL;
+ }
cbl->box_funcs = calloc(8, sizeof(cbl->box_funcs[0]));
- if ( cbl->box_funcs == NULL ) return NULL;
+ if ( cbl->box_funcs == NULL ) {
+ free(cbl->names);
+ free(cbl);
+ return NULL;
+ }
cbl->draw_funcs = calloc(8, sizeof(cbl->draw_funcs[0]));
- if ( cbl->draw_funcs == NULL ) return NULL;
+ if ( cbl->draw_funcs == NULL ) {
+ free(cbl->box_funcs);
+ free(cbl->names);
+ free(cbl);
+ return NULL;
+ }
cbl->click_funcs = calloc(8, sizeof(cbl->click_funcs[0]));
- if ( cbl->click_funcs == NULL ) return NULL;
+ if ( cbl->click_funcs == NULL ) {
+ free(cbl->draw_funcs);
+ free(cbl->box_funcs);
+ free(cbl->names);
+ free(cbl);
+ return NULL;
+ }
cbl->vps = calloc(8, sizeof(cbl->vps[0]));
- if ( cbl->vps == NULL ) return NULL;
+ if ( cbl->vps == NULL ) {
+ free(cbl->click_funcs);
+ free(cbl->draw_funcs);
+ free(cbl->box_funcs);
+ free(cbl->names);
+ free(cbl);
+ return NULL;
+ }
cbl->max_callbacks = 8;
cbl->n_callbacks = 0;
@@ -978,13 +1003,14 @@ static void output_frame(SCInterpreter *scin, SCBlock *bl, Stylesheet *ss,
char *result;
fr = add_subframe(sc_interp_get_frame(scin));
- fr->scblocks = bl;
- fr->resizable = 1;
if ( fr == NULL ) {
fprintf(stderr, _("Failed to add frame.\n"));
return;
}
+ fr->scblocks = bl;
+ fr->resizable = 1;
+
/* Lowest priority: current state of interpreter */
set_frame_default_style(fr, scin);
diff --git a/src/sc_parse.c b/src/sc_parse.c
index e8904a0..a0ec8a5 100644
--- a/src/sc_parse.c
+++ b/src/sc_parse.c
@@ -306,6 +306,8 @@ int sc_block_delete(SCBlock **top, SCBlock *deleteme)
/* Frees "bl" and all its children (but not the blocks following it) */
void sc_block_free(SCBlock *bl)
{
+ if ( bl == NULL ) return;
+
if ( bl->child != NULL ) {
SCBlock *ch = bl->child;
while ( ch != NULL ) {
@@ -370,6 +372,7 @@ char *serialise_sc_block(const SCBlock *bl)
ch = bl->child;
while ( ch != NULL ) {
+ char *anew;
char *c = serialise_sc_block(ch);
if ( c == NULL ) {
free(a);
@@ -377,8 +380,14 @@ char *serialise_sc_block(const SCBlock *bl)
}
len += strlen(c);
- a = realloc(a, len);
- if ( a == NULL ) return NULL;
+
+ anew = realloc(a, len);
+ if ( anew == NULL ) {
+ return NULL;
+ } else {
+ a = anew;
+ }
+
strcat(a, c);
free(c);
@@ -724,15 +733,27 @@ void sc_block_set_contents(SCBlock *bl, char *con)
void sc_insert_text(SCBlock *b1, size_t o1, const char *t)
{
+ size_t len;
+ char *cnew;
+ char *tmp;
+ char *p1;
+
if ( b1->contents == NULL ) {
b1->contents = strdup(t);
return;
}
- size_t len = strlen(b1->contents)+1+strlen(t);
- char *cnew = realloc(b1->contents, len);
- char *tmp = malloc(len);
- char *p1 = cnew + o1;
- if ( (cnew == NULL) || (tmp == NULL) ) return;
+ len = strlen(b1->contents)+1+strlen(t);
+
+ cnew = realloc(b1->contents, len);
+ if ( cnew == NULL ) return;
+
+ tmp = malloc(len);
+ if ( tmp == NULL ) {
+ free(cnew);
+ return;
+ }
+
+ p1 = cnew + o1;
strcpy(tmp, p1);
strcpy(p1, t);
strcpy(p1+strlen(t), tmp);
diff --git a/src/stylesheet.c b/src/stylesheet.c
index dbafd8c..a057935 100644
--- a/src/stylesheet.c
+++ b/src/stylesheet.c
@@ -104,12 +104,14 @@ Stylesheet *stylesheet_load(GFile *file)
if ( !g_file_load_contents(file, NULL, &everything, &len, NULL, NULL) ) {
fprintf(stderr, _("Failed to load stylesheet '%s'\n"),
g_file_get_uri(file));
+ free(ss);
return NULL;
}
r = json_parser_load_from_data(parser, everything, len, &err);
if ( r == FALSE ) {
fprintf(stderr, "Failed to load style sheet: '%s'\n", err->message);
+ free(ss);
return NULL;
}