aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2016-02-28 15:15:11 +0100
committerThomas White <taw@bitwiz.org.uk>2016-02-28 15:15:11 +0100
commitd3cabf1f4a72d64a1da12a4826bf4bea13e59289 (patch)
tree8f406a8ad7e7425f076242669703a55584512ca4
parentcfafd6eaced69313a0ffebc4f1dba9f6e99b2438 (diff)
Prevent NULL dereference
-rw-r--r--src/boxvec.c2
-rw-r--r--src/wrap.c4
2 files changed, 5 insertions, 1 deletions
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--;
}