Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

bugfix: _alloc while just arrive end

  • Loading branch information...
commit 2e9e76d86dc5f8d855b6dbdaaa3d0773e5df228b 1 parent acf47ec
@cloudwu authored
Showing with 18 additions and 5 deletions.
  1. +9 −5 ringbuffer.c
  2. +9 −0 testringbuffer.c
View
14 ringbuffer.c
@@ -69,12 +69,16 @@ _alloc(struct ringbuffer * rb, int total_size , int size) {
blk->next = -1;
blk->id = -1;
struct ringbuffer_block * next = block_next(rb, blk);
- rb->head = block_offset(rb, next);
- if (align_length < total_size) {
- next->length = total_size - align_length;
- if (next->length >= sizeof(struct ringbuffer_block)) {
- next->id = -1;
+ if (next) {
+ rb->head = block_offset(rb, next);
+ if (align_length < total_size) {
+ next->length = total_size - align_length;
+ if (next->length >= sizeof(struct ringbuffer_block)) {
+ next->id = -1;
+ }
}
+ } else {
+ rb->head = 0;
}
return blk;
}
View
9 testringbuffer.c
@@ -29,9 +29,18 @@ dump(struct ringbuffer * rb, struct ringbuffer_block *blk, int size) {
static void
test(struct ringbuffer *rb) {
struct ringbuffer_block * blk;
+ blk = ringbuffer_alloc(rb,48);
+ blk->id = 0;
+ ringbuffer_free(rb,blk);
+ blk = ringbuffer_alloc(rb,48);
+ blk->id = 1;
+ ringbuffer_free(rb,blk);
+
blk = ringbuffer_alloc(rb,80);
blk->id = 0;
ringbuffer_free(rb,blk);
+
+
blk = ringbuffer_alloc(rb,50);
blk->id = 1;
struct ringbuffer_block * next = ringbuffer_alloc(rb, 40);
Please sign in to comment.
Something went wrong with that request. Please try again.