Commit d48dd7ef authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

usp10: Use usp10_array_reserve() in computeBracketPairs().

parent 24f64acc
...@@ -694,6 +694,7 @@ static BracketPair *computeBracketPairs(IsolatedRun *iso_run) ...@@ -694,6 +694,7 @@ static BracketPair *computeBracketPairs(IsolatedRun *iso_run)
int stack_top = iso_run->length; int stack_top = iso_run->length;
unsigned int pair_count = 0; unsigned int pair_count = 0;
BracketPair *out = NULL; BracketPair *out = NULL;
SIZE_T out_size = 0;
int i; int i;
open_stack = heap_alloc(iso_run->length * sizeof(*open_stack)); open_stack = heap_alloc(iso_run->length * sizeof(*open_stack));
...@@ -702,42 +703,43 @@ static BracketPair *computeBracketPairs(IsolatedRun *iso_run) ...@@ -702,42 +703,43 @@ static BracketPair *computeBracketPairs(IsolatedRun *iso_run)
for (i = 0; i < iso_run->length; i++) for (i = 0; i < iso_run->length; i++)
{ {
unsigned short ubv = get_table_entry(bidi_bracket_table, iso_run->item[i].ch); unsigned short ubv = get_table_entry(bidi_bracket_table, iso_run->item[i].ch);
if (ubv)
if (!ubv)
continue;
if ((ubv >> 8) == 0)
{ {
if (!out) --stack_top;
{ open_stack[stack_top] = iso_run->item[i].ch + (signed char)(ubv & 0xff);
out = heap_alloc(sizeof(*out)); /* Deal with canonical equivalent U+2329/232A and U+3008/3009. */
out[0].start = -1; if (open_stack[stack_top] == 0x232a)
} open_stack[stack_top] = 0x3009;
stack_index[stack_top] = i;
}
else if ((ubv >> 8) == 1)
{
unsigned int j;
if ((ubv >> 8) == 0) for (j = stack_top; j < iso_run->length; ++j)
{
stack_top --;
open_stack[stack_top] = iso_run->item[i].ch + (signed char)(ubv & 0xff);
/* deal with canonical equivalent U+2329/232A and U+3008/3009 */
if (open_stack[stack_top] == 0x232A)
open_stack[stack_top] = 0x3009;
stack_index[stack_top] = i;
}
else if ((ubv >> 8) == 1)
{ {
int j; WCHAR c = iso_run->item[i].ch;
if (stack_top == iso_run->length) continue;
for (j = stack_top; j < iso_run->length; j++) if (c == 0x232a)
{ c = 0x3009;
WCHAR c = iso_run->item[i].ch;
if (c == 0x232A) c = 0x3009; if (c != open_stack[j])
if (c == open_stack[j]) continue;
{
out[pair_count].start = stack_index[j]; if (!(usp10_array_reserve((void **)&out, &out_size, pair_count + 2, sizeof(*out))))
out[pair_count].end = i; ERR("Failed to grow output array.\n");
pair_count++;
out = HeapReAlloc(GetProcessHeap(), 0, out, sizeof(BracketPair) * (pair_count+1)); out[pair_count].start = stack_index[j];
out[pair_count].start = -1; out[pair_count].end = i;
stack_top = j+1; ++pair_count;
break;
} out[pair_count].start = -1;
} stack_top = j + 1;
break;
} }
} }
} }
...@@ -746,10 +748,7 @@ static BracketPair *computeBracketPairs(IsolatedRun *iso_run) ...@@ -746,10 +748,7 @@ static BracketPair *computeBracketPairs(IsolatedRun *iso_run)
heap_free(stack_index); heap_free(stack_index);
if (!pair_count) if (!pair_count)
{
heap_free(out);
return NULL; return NULL;
}
qsort(out, pair_count, sizeof(*out), compr); qsort(out, pair_count, sizeof(*out), compr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment