From d3cabf1f4a72d64a1da12a4826bf4bea13e59289 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 28 Feb 2016 15:15:11 +0100 Subject: Prevent NULL dereference --- src/boxvec.c | 2 ++ src/wrap.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/boxvec.c b/src/boxvec.c index 7cdd01c..f00a81c 100644 --- a/src/boxvec.c +++ b/src/boxvec.c @@ -85,6 +85,8 @@ struct wrap_box *bv_box(struct boxvec *vec, int i) struct wrap_box *bv_last(struct boxvec *vec) { + if ( vec == NULL ) return NULL; + if ( vec->boxes == NULL ) return NULL; return vec->boxes[vec->n_boxes-1]; } diff --git a/src/wrap.c b/src/wrap.c index 018f9e3..6389905 100644 --- a/src/wrap.c +++ b/src/wrap.c @@ -960,7 +960,9 @@ int wrap_contents(struct frame *fr) //distribute_spaces(line, wrap_w, rho); /* Strip any sentinel boxes added by the wrapping algorithm */ - if ( bv_last(line->boxes)->type == WRAP_BOX_SENTINEL ) { + if ( (bv_last(line->boxes) != NULL) + && (bv_last(line->boxes)->type == WRAP_BOX_SENTINEL) ) + { line->boxes->n_boxes--; } -- cgit v1.2.3