mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-15 01:52:42 +03:00
ur: assert not-null after all allocations
This commit is contained in:
parent
844ed22a2e
commit
562548440b
@ -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;
|
uint64_t i, next = prev + size;
|
||||||
|
|
||||||
buckets = calloc(next, sizeof(*buckets));
|
buckets = calloc(next, sizeof(*buckets));
|
||||||
|
assert( buckets );
|
||||||
|
|
||||||
if ( old_buckets ) {
|
if ( old_buckets ) {
|
||||||
for ( i = 0; i < old_size; i++ ) {
|
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;
|
uint64_t i, next = prev + size;
|
||||||
|
|
||||||
buckets = calloc(next, sizeof(*buckets));
|
buckets = calloc(next, sizeof(*buckets));
|
||||||
|
assert( buckets );
|
||||||
|
|
||||||
if ( old_buckets ) {
|
if ( old_buckets ) {
|
||||||
for ( i = 0; i < old_size; i++ ) {
|
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;
|
uint64_t i, next = prev + size;
|
||||||
|
|
||||||
buckets = calloc(next, sizeof(*buckets));
|
buckets = calloc(next, sizeof(*buckets));
|
||||||
|
assert( buckets );
|
||||||
|
|
||||||
if ( old_buckets ) {
|
if ( old_buckets ) {
|
||||||
for ( i = 0; i < old_size; i++ ) {
|
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)
|
atoms->bytes = malloc(next * ( sizeof(*atoms->bytes)
|
||||||
+ sizeof(*atoms->lens)
|
+ sizeof(*atoms->lens)
|
||||||
+ sizeof(*atoms->mugs) ));
|
+ sizeof(*atoms->mugs) ));
|
||||||
|
assert( atoms->bytes );
|
||||||
|
|
||||||
atoms->lens = (void*)((char*)atoms->bytes + (next * sizeof(*atoms->bytes)));
|
atoms->lens = (void*)((char*)atoms->bytes + (next * sizeof(*atoms->bytes)));
|
||||||
atoms->mugs = (void*)((char*)atoms->lens + (next * sizeof(*atoms->lens)));
|
atoms->mugs = (void*)((char*)atoms->lens + (next * sizeof(*atoms->lens)));
|
||||||
|
|
||||||
assert( atoms->bytes );
|
|
||||||
|
|
||||||
if ( bytes ) {
|
if ( bytes ) {
|
||||||
memcpy(atoms->bytes, bytes, size * (sizeof(*bytes)));
|
memcpy(atoms->bytes, bytes, size * (sizeof(*bytes)));
|
||||||
memcpy(atoms->lens, lens, size * (sizeof(*lens)));
|
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)
|
cells->heads = malloc(next * ( sizeof(*cells->heads)
|
||||||
+ sizeof(*cells->heads)
|
+ sizeof(*cells->heads)
|
||||||
+ sizeof(*cells->mugs) ));
|
+ sizeof(*cells->mugs) ));
|
||||||
|
assert( cells->heads );
|
||||||
|
|
||||||
cells->tails = (void*)((char*)cells->heads + (next * sizeof(*cells->heads)));
|
cells->tails = (void*)((char*)cells->heads + (next * sizeof(*cells->heads)));
|
||||||
cells->mugs = (void*)((char*)cells->tails + (next * sizeof(*cells->tails)));
|
cells->mugs = (void*)((char*)cells->tails + (next * sizeof(*cells->tails)));
|
||||||
|
|
||||||
assert( cells->heads );
|
|
||||||
|
|
||||||
if ( heads ) {
|
if ( heads ) {
|
||||||
memcpy(cells->heads, heads, size * (sizeof(*heads)));
|
memcpy(cells->heads, heads, size * (sizeof(*heads)));
|
||||||
memcpy(cells->tails, tails, size * (sizeof(*tails)));
|
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->fill = 0;
|
||||||
v->refs = calloc(size, sizeof(ur_nref));
|
v->refs = calloc(size, sizeof(ur_nref));
|
||||||
|
assert( v->refs );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -927,6 +931,7 @@ ur_walk_fore(ur_root_t *r,
|
|||||||
ur_nref *top, *don;
|
ur_nref *top, *don;
|
||||||
|
|
||||||
don = malloc(size * sizeof(*don));
|
don = malloc(size * sizeof(*don));
|
||||||
|
assert( don );
|
||||||
top = don + ++fill;
|
top = don + ++fill;
|
||||||
*top = ref;
|
*top = ref;
|
||||||
|
|
||||||
@ -952,6 +957,7 @@ ur_walk_fore(ur_root_t *r,
|
|||||||
if ( size == fill ) {
|
if ( size == fill ) {
|
||||||
uint64_t next = prev + size;
|
uint64_t next = prev + size;
|
||||||
don = realloc(don, next * sizeof(*don));
|
don = realloc(don, next * sizeof(*don));
|
||||||
|
assert( don );
|
||||||
top = don + fill;
|
top = don + fill;
|
||||||
prev = size;
|
prev = size;
|
||||||
size = next;
|
size = next;
|
||||||
|
@ -82,6 +82,7 @@ ur_jam_unsafe(ur_root_t *r,
|
|||||||
j.bsw.prev = ur_fib11;
|
j.bsw.prev = ur_fib11;
|
||||||
j.bsw.size = ur_fib12;
|
j.bsw.size = ur_fib12;
|
||||||
j.bsw.bytes = calloc(j.bsw.size, 1);
|
j.bsw.bytes = calloc(j.bsw.size, 1);
|
||||||
|
assert( j.bsw.bytes );
|
||||||
|
|
||||||
ur_walk_fore(r, ref, &j, _jam_atom, _jam_cell);
|
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 ) {
|
if ( s->fill == s->size ) {
|
||||||
uint32_t next = s->prev + s->size;
|
uint32_t next = s->prev + s->size;
|
||||||
s->f = realloc(s->f, next * sizeof(*s->f));
|
s->f = realloc(s->f, next * sizeof(*s->f));
|
||||||
|
assert( s->f );
|
||||||
s->prev = s->size;
|
s->prev = s->size;
|
||||||
s->size = next;
|
s->size = next;
|
||||||
}
|
}
|
||||||
@ -193,6 +195,8 @@ _cue_next(ur_root_t *r,
|
|||||||
else {
|
else {
|
||||||
uint64_t len_byt = (len >> 3) + !!ur_mask_3(len);
|
uint64_t len_byt = (len >> 3) + !!ur_mask_3(len);
|
||||||
uint8_t *byt = calloc(len_byt, 1);
|
uint8_t *byt = calloc(len_byt, 1);
|
||||||
|
assert( byt );
|
||||||
|
|
||||||
ur_bsr_bytes_any(bsr, len, byt);
|
ur_bsr_bytes_any(bsr, len, byt);
|
||||||
|
|
||||||
// strip trailing zeroes
|
// strip trailing zeroes
|
||||||
@ -239,6 +243,7 @@ ur_cue_unsafe(ur_root_t *r,
|
|||||||
s.prev = ur_fib10;
|
s.prev = ur_fib10;
|
||||||
s.size = ur_fib11;
|
s.size = ur_fib11;
|
||||||
s.f = malloc(s.size * sizeof(*s.f));
|
s.f = malloc(s.size * sizeof(*s.f));
|
||||||
|
assert( s.f );
|
||||||
|
|
||||||
// advance into stream
|
// advance into stream
|
||||||
//
|
//
|
||||||
@ -331,6 +336,7 @@ _cue_test_next(_cue_test_stack_t *s,
|
|||||||
if ( s->fill == s->size ) {
|
if ( s->fill == s->size ) {
|
||||||
uint32_t next = s->prev + s->size;
|
uint32_t next = s->prev + s->size;
|
||||||
s->f = realloc(s->f, next * sizeof(*s->f));
|
s->f = realloc(s->f, next * sizeof(*s->f));
|
||||||
|
assert( s->f );
|
||||||
s->prev = s->size;
|
s->prev = s->size;
|
||||||
s->size = next;
|
s->size = next;
|
||||||
}
|
}
|
||||||
@ -398,6 +404,7 @@ ur_cue_test_unsafe(ur_dict_t *dict,
|
|||||||
s.prev = ur_fib10;
|
s.prev = ur_fib10;
|
||||||
s.size = ur_fib11;
|
s.size = ur_fib11;
|
||||||
s.f = malloc(s.size * sizeof(*s.f));
|
s.f = malloc(s.size * sizeof(*s.f));
|
||||||
|
assert( s.f );
|
||||||
|
|
||||||
// advance into stream
|
// advance into stream
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user