From 5236d9d5009e78aa38c02a98a59e821b36ae9037 Mon Sep 17 00:00:00 2001 From: Erwin Janssen Date: Sat, 19 Nov 2016 02:20:46 +0100 Subject: [PATCH] Fixed: 'dereference before null check' in DotIO.c When the local variables in the function `convert_edge_labels_to_nodes` in lib/spare/DotIO.c are initialized, the pointer `g` is dereferenced. But a the check that tests if `g` is NULL happens after this initialization. The fix is placing the `if (!g) return NULL` as the first line of the function, so dereferencing only occurs if the pointer is not NULL. --- lib/sparse/DotIO.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/sparse/DotIO.c b/lib/sparse/DotIO.c index 3b2da494f..6e89c5c41 100644 --- a/lib/sparse/DotIO.c +++ b/lib/sparse/DotIO.c @@ -676,6 +676,8 @@ char *cat_string3(char *s1, char *s2, char *s3, int id){ Agraph_t *convert_edge_labels_to_nodes(Agraph_t* g){ + if (!g) return NULL; + Agnode_t *n, *newnode; Agraph_t *dg; @@ -694,7 +696,6 @@ Agraph_t *convert_edge_labels_to_nodes(Agraph_t* g){ dg = agopen("test", g->desc, 0); - if (!g) return NULL; nnodes = agnnodes (g); nedges = agnedges (g); -- 2.40.0