ur: assert not-null after all allocations

This commit is contained in:
Joe Bryan 2020-09-08 13:20:43 -07:00
parent 844ed22a2e
commit 562548440b
2 changed files with 17 additions and 4 deletions

View File

@ -25,6 +25,7 @@ ur_dict32_grow(ur_root_t *r, ur_dict32_t *dict, uint64_t prev, uint64_t size)
uint64_t i, next = prev + size;
buckets = calloc(next, sizeof(*buckets));
assert( buckets );
if ( old_buckets ) {
for ( i = 0; i < old_size; i++ ) {
@ -126,6 +127,7 @@ ur_dict64_grow(ur_root_t *r, ur_dict64_t *dict, uint64_t prev, uint64_t size)
uint64_t i, next = prev + size;
buckets = calloc(next, sizeof(*buckets));
assert( buckets );
if ( old_buckets ) {
for ( i = 0; i < old_size; i++ ) {
@ -227,6 +229,7 @@ ur_dict_grow(ur_root_t *r, ur_dict_t *dict, uint64_t prev, uint64_t size)
uint64_t i, next = prev + size;
buckets = calloc(next, sizeof(*buckets));
assert( buckets );
if ( old_buckets ) {
for ( i = 0; i < old_size; i++ ) {
@ -425,11 +428,11 @@ ur_atoms_grow(ur_atoms_t *atoms)
atoms->bytes = malloc(next * ( sizeof(*atoms->bytes)
+ sizeof(*atoms->lens)
+ sizeof(*atoms->mugs) ));
assert( atoms->bytes );
atoms->lens = (void*)((char*)atoms->bytes + (next * sizeof(*atoms->bytes)));
atoms->mugs = (void*)((char*)atoms->lens + (next * sizeof(*atoms->lens)));
assert( atoms->bytes );
if ( bytes ) {
memcpy(atoms->bytes, bytes, size * (sizeof(*bytes)));
memcpy(atoms->lens, lens, size * (sizeof(*lens)));
@ -455,11 +458,11 @@ ur_cells_grow(ur_cells_t *cells)
cells->heads = malloc(next * ( sizeof(*cells->heads)
+ sizeof(*cells->heads)
+ sizeof(*cells->mugs) ));
assert( cells->heads );
cells->tails = (void*)((char*)cells->heads + (next * sizeof(*cells->heads)));
cells->mugs = (void*)((char*)cells->tails + (next * sizeof(*cells->tails)));
assert( cells->heads );
if ( heads ) {
memcpy(cells->heads, heads, size * (sizeof(*heads)));
memcpy(cells->tails, tails, size * (sizeof(*tails)));
@ -914,6 +917,7 @@ ur_nvec_init(ur_nvec_t *v, uint64_t size)
{
v->fill = 0;
v->refs = calloc(size, sizeof(ur_nref));
assert( v->refs );
}
void
@ -927,6 +931,7 @@ ur_walk_fore(ur_root_t *r,
ur_nref *top, *don;
don = malloc(size * sizeof(*don));
assert( don );
top = don + ++fill;
*top = ref;
@ -952,6 +957,7 @@ ur_walk_fore(ur_root_t *r,
if ( size == fill ) {
uint64_t next = prev + size;
don = realloc(don, next * sizeof(*don));
assert( don );
top = don + fill;
prev = size;
size = next;

View File

@ -82,6 +82,7 @@ ur_jam_unsafe(ur_root_t *r,
j.bsw.prev = ur_fib11;
j.bsw.size = ur_fib12;
j.bsw.bytes = calloc(j.bsw.size, 1);
assert( j.bsw.bytes );
ur_walk_fore(r, ref, &j, _jam_atom, _jam_cell);
@ -150,6 +151,7 @@ _cue_next(ur_root_t *r,
if ( s->fill == s->size ) {
uint32_t next = s->prev + s->size;
s->f = realloc(s->f, next * sizeof(*s->f));
assert( s->f );
s->prev = s->size;
s->size = next;
}
@ -193,6 +195,8 @@ _cue_next(ur_root_t *r,
else {
uint64_t len_byt = (len >> 3) + !!ur_mask_3(len);
uint8_t *byt = calloc(len_byt, 1);
assert( byt );
ur_bsr_bytes_any(bsr, len, byt);
// strip trailing zeroes
@ -239,6 +243,7 @@ ur_cue_unsafe(ur_root_t *r,
s.prev = ur_fib10;
s.size = ur_fib11;
s.f = malloc(s.size * sizeof(*s.f));
assert( s.f );
// advance into stream
//
@ -331,6 +336,7 @@ _cue_test_next(_cue_test_stack_t *s,
if ( s->fill == s->size ) {
uint32_t next = s->prev + s->size;
s->f = realloc(s->f, next * sizeof(*s->f));
assert( s->f );
s->prev = s->size;
s->size = next;
}
@ -398,6 +404,7 @@ ur_cue_test_unsafe(ur_dict_t *dict,
s.prev = ur_fib10;
s.size = ur_fib11;
s.f = malloc(s.size * sizeof(*s.f));
assert( s.f );
// advance into stream
//