diff options
-rw-r--r-- | apps/buffering.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/apps/buffering.c b/apps/buffering.c index 97f85dfbc7..0325d4e4f3 100644 --- a/apps/buffering.c +++ b/apps/buffering.c | |||
@@ -216,8 +216,9 @@ buf_ridx == buf_widx means the buffer is empty. | |||
216 | alloc_all tells us if we must immediately be able to allocate data_size | 216 | alloc_all tells us if we must immediately be able to allocate data_size |
217 | returns a valid memory handle if all conditions for allocation are met. | 217 | returns a valid memory handle if all conditions for allocation are met. |
218 | NULL if there memory_handle itself cannot be allocated or if the | 218 | NULL if there memory_handle itself cannot be allocated or if the |
219 | data_size cannot be allocated and alloc_all is set. This function | 219 | data_size cannot be allocated and alloc_all is set. This function's |
220 | has no side effects if NULL is returned. | 220 | only potential side effect is to allocate space for the cur_handle |
221 | if it returns NULL. | ||
221 | */ | 222 | */ |
222 | static struct memory_handle *add_handle(size_t data_size, const bool can_wrap, | 223 | static struct memory_handle *add_handle(size_t data_size, const bool can_wrap, |
223 | const bool alloc_all) | 224 | const bool alloc_all) |
@@ -225,7 +226,7 @@ static struct memory_handle *add_handle(size_t data_size, const bool can_wrap, | |||
225 | /* gives each handle a unique id, unsigned to handle wraps gracefully */ | 226 | /* gives each handle a unique id, unsigned to handle wraps gracefully */ |
226 | static unsigned int cur_handle_id = 1; | 227 | static unsigned int cur_handle_id = 1; |
227 | size_t shift; | 228 | size_t shift; |
228 | size_t new_widx = buf_widx; | 229 | size_t new_widx; |
229 | size_t len; | 230 | size_t len; |
230 | int overlap; | 231 | int overlap; |
231 | 232 | ||
@@ -242,12 +243,12 @@ static struct memory_handle *add_handle(size_t data_size, const bool can_wrap, | |||
242 | return NULL; | 243 | return NULL; |
243 | } else { | 244 | } else { |
244 | /* Allocate the remainder of the space for the current handle */ | 245 | /* Allocate the remainder of the space for the current handle */ |
245 | new_widx = RINGBUF_ADD(cur_handle->widx, cur_handle->filerem); | 246 | buf_widx = RINGBUF_ADD(cur_handle->widx, cur_handle->filerem); |
246 | } | 247 | } |
247 | } | 248 | } |
248 | 249 | ||
249 | /* align buf_widx to 4 bytes up */ | 250 | /* align to 4 bytes up */ |
250 | new_widx = (RINGBUF_ADD(new_widx, 3)) & ~3; | 251 | new_widx = RINGBUF_ADD(buf_widx, 3) & ~3; |
251 | 252 | ||
252 | len = data_size + sizeof(struct memory_handle); | 253 | len = data_size + sizeof(struct memory_handle); |
253 | 254 | ||
@@ -265,7 +266,7 @@ static struct memory_handle *add_handle(size_t data_size, const bool can_wrap, | |||
265 | new_widx += data_size - overlap; | 266 | new_widx += data_size - overlap; |
266 | } | 267 | } |
267 | 268 | ||
268 | /* This is how far we shifted buf_widx to align things */ | 269 | /* How far we shifted buf_widx to align things, must be < buffer_len */ |
269 | shift = RINGBUF_SUB(new_widx, buf_widx); | 270 | shift = RINGBUF_SUB(new_widx, buf_widx); |
270 | 271 | ||
271 | /* How much space are we short in the actual ring buffer? */ | 272 | /* How much space are we short in the actual ring buffer? */ |