From: Erwin Janssen Date: Sat, 19 Nov 2016 01:06:57 +0000 (+0100) Subject: Fixed: 2 'dereference before null check' in SparseMatrix X-Git-Tag: 2.42.0~229^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0853d73b46f525d5ee78daad4ebc7de966ff3ed5;p=graphviz Fixed: 2 'dereference before null check' in SparseMatrix In the file lib/sparse/SparseMatric.x, there were two functions were a pointer is dereferenced before checking if the pointer is NULL. The check `if(!A)` caused an early return in both functions. The fix is placing the check and the early return as the first line in both functions. Dereferencing then only occures if the pointer A is not NULL. --- diff --git a/lib/sparse/SparseMatrix.c b/lib/sparse/SparseMatrix.c index c5d37f495..777c9085f 100644 --- a/lib/sparse/SparseMatrix.c +++ b/lib/sparse/SparseMatrix.c @@ -67,11 +67,12 @@ SparseMatrix SparseMatrix_make_undirected(SparseMatrix A){ return SparseMatrix_remove_upper(B); } SparseMatrix SparseMatrix_transpose(SparseMatrix A){ + if (!A) return NULL; + int *ia = A->ia, *ja = A->ja, *ib, *jb, nz = A->nz, m = A->m, n = A->n, type = A->type, format = A->format; SparseMatrix B; int i, j; - if (!A) return NULL; assert(A->format == FORMAT_CSR);/* only implemented for CSR right now */ B = SparseMatrix_new(n, m, nz, type, format); @@ -175,6 +176,8 @@ SparseMatrix SparseMatrix_symmetrize_nodiag(SparseMatrix A, int pattern_symmetri } int SparseMatrix_is_symmetric(SparseMatrix A, int test_pattern_symmetry_only){ + if (!A) return FALSE; + /* assume no repeated entries! */ SparseMatrix B; int *ia, *ja, *ib, *jb, type, m; @@ -183,8 +186,6 @@ int SparseMatrix_is_symmetric(SparseMatrix A, int test_pattern_symmetry_only){ int i, j; assert(A->format == FORMAT_CSR);/* only implemented for CSR right now */ - if (!A) return FALSE; - if (SparseMatrix_known_symmetric(A)) return TRUE; if (test_pattern_symmetry_only && SparseMatrix_known_strucural_symmetric(A)) return TRUE;