comparison circbuffer.c @ 1511:5916af64acd4 fuzz

merge from main
author Matt Johnston <matt@ucc.asn.au>
date Sat, 17 Feb 2018 19:29:51 +0800
parents 06d52bcb8094
children
comparison
equal deleted inserted replaced
1457:32f990cc96b1 1511:5916af64acd4
54 m_free(cbuf->data); 54 m_free(cbuf->data);
55 } 55 }
56 m_free(cbuf); 56 m_free(cbuf);
57 } 57 }
58 58
59 unsigned int cbuf_getused(circbuffer * cbuf) { 59 unsigned int cbuf_getused(const circbuffer * cbuf) {
60 60
61 return cbuf->used; 61 return cbuf->used;
62 62
63 } 63 }
64 64
65 unsigned int cbuf_getavail(circbuffer * cbuf) { 65 unsigned int cbuf_getavail(const circbuffer * cbuf) {
66 66
67 return cbuf->size - cbuf->used; 67 return cbuf->size - cbuf->used;
68 68
69 } 69 }
70 70
71 unsigned int cbuf_writelen(circbuffer *cbuf) { 71 unsigned int cbuf_writelen(const circbuffer *cbuf) {
72 72
73 dropbear_assert(cbuf->used <= cbuf->size); 73 dropbear_assert(cbuf->used <= cbuf->size);
74 dropbear_assert(((2*cbuf->size)+cbuf->writepos-cbuf->readpos)%cbuf->size == cbuf->used%cbuf->size); 74 dropbear_assert(((2*cbuf->size)+cbuf->writepos-cbuf->readpos)%cbuf->size == cbuf->used%cbuf->size);
75 dropbear_assert(((2*cbuf->size)+cbuf->readpos-cbuf->writepos)%cbuf->size == (cbuf->size-cbuf->used)%cbuf->size); 75 dropbear_assert(((2*cbuf->size)+cbuf->readpos-cbuf->writepos)%cbuf->size == (cbuf->size-cbuf->used)%cbuf->size);
76 76
84 } 84 }
85 85
86 return cbuf->size - cbuf->writepos; 86 return cbuf->size - cbuf->writepos;
87 } 87 }
88 88
89 void cbuf_readptrs(circbuffer *cbuf, 89 void cbuf_readptrs(const circbuffer *cbuf,
90 unsigned char **p1, unsigned int *len1, 90 unsigned char **p1, unsigned int *len1,
91 unsigned char **p2, unsigned int *len2) { 91 unsigned char **p2, unsigned int *len2) {
92 *p1 = &cbuf->data[cbuf->readpos]; 92 *p1 = &cbuf->data[cbuf->readpos];
93 *len1 = MIN(cbuf->used, cbuf->size - cbuf->readpos); 93 *len1 = MIN(cbuf->used, cbuf->size - cbuf->readpos);
94 94