We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi, In buffer. c, the handling of overflow situations by the buffer_push_tail function is as follows:
if (tail_end < rb->tail) { if (rb->head < align_size) { LOGE("no enough space"); return -1; } int *p = (int*)(rb->data + rb->tail); *p = size; memcpy(rb->data, data, size); rb->tail = size; }
Size is the true length of the data and is not aligned.
The text was updated successfully, but these errors were encountered:
My modification is like this:
int buffer_push_tail(Buffer* rb, const uint8_t* data, int size) { int free_space = (rb->size + rb->head - rb->tail - 1) % rb->size; int align_size = ALIGN32(size) + 4; if (align_size > free_space) { LOGE("no enough space"); return -1; } int tail_end = (rb->tail + align_size) % rb->size; if (tail_end < rb->tail) { if (rb->head < align_size) { LOGE("no enough space"); return -1; } int* p = (int*)(rb->data + rb->tail); *p = size; memcpy(rb->data, data, size); rb->tail = ALIGN32(size); } else { int* p = (int*)(rb->data + rb->tail); *p = size; memcpy(rb->data + rb->tail + 4, data, size); rb->tail = tail_end; } return size; } uint8_t* buffer_peak_head(Buffer* rb, int* size) { if (!rb || rb->head == rb->tail) { return NULL; } *size = *((int*)(rb->data + rb->head)); int align_size = ALIGN32(*size) + 4; int head_end = (rb->head + align_size) % rb->size; if (head_end < rb->head) { return rb->data; } else { return rb->data + (rb->head + 4); } } void buffer_pop_head(Buffer* rb) { if (!rb || rb->head == rb->tail) { return; } int* size = (int*)(rb->data + rb->head); int align_size = ALIGN32(*size) + 4; int head_end = (rb->head + align_size) % rb->size; if (head_end < rb->head) { rb->head = ALIGN32(*size); } else { rb->head = rb->head + align_size; } }
This modification is relatively simple but wastes space. Let's see if we need to further optimize it.
Sorry, something went wrong.
No branches or pull requests
Hi,
In buffer. c, the handling of overflow situations by the buffer_push_tail function is as follows:
Size is the true length of the data and is not aligned.
The text was updated successfully, but these errors were encountered: