diff options
author | Thomas White <taw@physics.org> | 2015-10-16 10:48:24 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2015-10-16 10:48:24 +0200 |
commit | e7fc7858e8118de0da38bddbc70d3914b7f0cfcc (patch) | |
tree | 78507d2f774662e48bbdec53bb8810e8ddaee1cb /src/wrap.c | |
parent | 779a3436b14d3152e376949fb1294cb62e46a4d7 (diff) |
Allocate boxes in line properly during wrapping
Diffstat (limited to 'src/wrap.c')
-rw-r--r-- | src/wrap.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -55,17 +55,18 @@ static void alloc_lines(struct frame *fr) } -void alloc_boxes(struct wrap_line *l) +int alloc_boxes(struct wrap_line *l) { struct wrap_box *boxes_new; boxes_new = realloc(l->boxes, l->max_boxes * sizeof(struct wrap_box)); if ( boxes_new == NULL ) { fprintf(stderr, "Couldn't allocate memory for boxes!\n"); - return; + return 1; } l->boxes = boxes_new; + return 0; } @@ -734,6 +735,15 @@ static struct wrap_line *new_line(struct frame *fr) } +static int maybe_extend_line(struct wrap_line *l) +{ + if ( l->n_boxes < l->max_boxes ) return 0; + + l->max_boxes += 32; + return alloc_boxes(l); +} + + static void first_fit(struct wrap_line *boxes, double line_length, struct frame *fr) { @@ -759,6 +769,7 @@ static void first_fit(struct wrap_line *boxes, double line_length, line->boxes[line->n_boxes] = boxes->boxes[j]; line->boxes[line->n_boxes].cf = &boxes->boxes[j]; line->n_boxes++; + if ( maybe_extend_line(line) ) return; j++; if ( (j > 0) && (boxes->boxes[j-1].type != WRAP_BOX_SENTINEL) ) |