diff options
author | Thomas White <taw@bitwiz.me.uk> | 2019-03-10 15:43:42 +0100 |
---|---|---|
committer | Thomas White <taw@bitwiz.me.uk> | 2019-03-10 15:43:42 +0100 |
commit | 1d0df409c6d00dec67f3ec60674219bce30592a0 (patch) | |
tree | 6b48ba067cc75477b3b3e2e5a5220ca9594bfe2a /libstorycode/narrative.c | |
parent | 0e88cfed0e00a34436c4db3c9b2b8ad422c5a2df (diff) |
Fix some range errors with selection
Diffstat (limited to 'libstorycode/narrative.c')
-rw-r--r-- | libstorycode/narrative.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/libstorycode/narrative.c b/libstorycode/narrative.c index f32e8f0..fe1cf0c 100644 --- a/libstorycode/narrative.c +++ b/libstorycode/narrative.c @@ -156,6 +156,7 @@ static void delete_item(Narrative *n, int del) void narrative_delete_block(Narrative *n, int i1, size_t o1, int i2, size_t o2) { int i; + int n_del = 0; int merge = 1; /* Starting item */ @@ -177,9 +178,12 @@ void narrative_delete_block(Narrative *n, int i1, size_t o1, int i2, size_t o2) /* Middle items */ for ( i=i1+1; i<i2; i++ ) { - delete_item(n, i); - i2--; + /* Deleting the item moves all the subsequent items up, so the + * index to be deleted doesn't change. */ + delete_item(n, i1+1); + n_del++; } + i2 -= n_del; /* Last item */ if ( n->items[i2].type == NARRATIVE_ITEM_SLIDE ) { |