summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/buffering.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/apps/buffering.c b/apps/buffering.c
index c59fc52b8a..e55e81da45 100644
--- a/apps/buffering.c
+++ b/apps/buffering.c
@@ -996,6 +996,7 @@ static struct memory_handle *prep_bufdata(int handle_id, size_t *size,
996 /* If more than the size of the guardbuf is requested and this is a 996 /* If more than the size of the guardbuf is requested and this is a
997 * bufgetdata, limit to guard_bufsize over the end of the buffer */ 997 * bufgetdata, limit to guard_bufsize over the end of the buffer */
998 *size = MIN(*size, buffer_len - h->ridx + GUARD_BUFSIZE); 998 *size = MIN(*size, buffer_len - h->ridx + GUARD_BUFSIZE);
999 /* this ensures *size <= buffer_len - h->ridx + GUARD_BUFSIZE */
999 } 1000 }
1000 1001
1001 if (h->filerem > 0 && avail < *size) 1002 if (h->filerem > 0 && avail < *size)
@@ -1068,9 +1069,10 @@ ssize_t bufgetdata(int handle_id, size_t size, void **data)
1068 { 1069 {
1069 /* the data wraps around the end of the buffer : 1070 /* the data wraps around the end of the buffer :
1070 use the guard buffer to provide the requested amount of data. */ 1071 use the guard buffer to provide the requested amount of data. */
1071 size_t copy_n = MIN(h->ridx + size - buffer_len, GUARD_BUFSIZE); 1072 size_t copy_n = h->ridx + size - buffer_len;
1073 /* prep_bufdata ensures size <= buffer_len - h->ridx + GUARD_BUFSIZE,
1074 so copy_n <= GUARD_BUFSIZE */
1072 memcpy(guard_buffer, (unsigned char *)buffer, copy_n); 1075 memcpy(guard_buffer, (unsigned char *)buffer, copy_n);
1073 size = buffer_len - h->ridx + copy_n;
1074 } 1076 }
1075 1077
1076 *data = &buffer[h->ridx]; 1078 *data = &buffer[h->ridx];