Increase size of ref_counts and add assertions
This bumps the size of the reference counts from 16- to 32-bit counters to make it less likely to overflow. Also assert in the retain function that the reference count didn't overflow. 32-bits seems big enough for non-pathological examples but a more fool-proof fix may be to bump it to 64-bits.
This commit is contained in:
parent
839dc53bf2
commit
5ef9c4d6aa
3 changed files with 5 additions and 3 deletions
|
|
@ -26,7 +26,7 @@ struct StackNode {
|
|||
Length position;
|
||||
StackLink links[MAX_LINK_COUNT];
|
||||
short unsigned int link_count;
|
||||
short unsigned int ref_count;
|
||||
uint32_t ref_count;
|
||||
unsigned error_cost;
|
||||
unsigned error_count;
|
||||
};
|
||||
|
|
@ -65,8 +65,9 @@ struct Stack {
|
|||
static void stack_node_retain(StackNode *self) {
|
||||
if (!self)
|
||||
return;
|
||||
assert(self->ref_count != 0);
|
||||
assert(self->ref_count > 0);
|
||||
self->ref_count++;
|
||||
assert(self->ref_count != 0);
|
||||
}
|
||||
|
||||
static void stack_node_release(StackNode *self, StackNodeArray *pool) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue