From 8e108e1e513f8bcaeb90c22915afdac426e7782d Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Wed, 13 Aug 2008 16:25:54 +0000 Subject: Fix segfault in elimination of duplicate attributes. svn path=/trunk/hubbub/; revision=5098 --- src/tokeniser/tokeniser.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/tokeniser/tokeniser.c') diff --git a/src/tokeniser/tokeniser.c b/src/tokeniser/tokeniser.c index 755b3b5..1fdaddb 100644 --- a/src/tokeniser/tokeniser.c +++ b/src/tokeniser/tokeniser.c @@ -2861,19 +2861,20 @@ hubbub_error emit_current_tag(hubbub_tokeniser *tokeniser) continue; } + assert(i < j); + /* Calculate amount to move */ - move = (n_attributes - 1 - - ((i < j) ? j : i)) * + move = (n_attributes - 1 - j) * sizeof(hubbub_attribute); if (move > 0) { - memmove((i < j) ? &attrs[j] - : &attrs[i], - (i < j) ? &attrs[j+1] - : &attrs[i+1], - move); + memmove(&attrs[j],&attrs[j+1], move); } + /* We've deleted an item, so we need to + * reprocess this index */ + j--; + /* And reduce the number of attributes */ n_attributes--; } -- cgit v1.2.3