@@ -9,19 +9,17 @@ static void sbappendsb(struct sbuf *sb, struct mbuf *m);
9
9
10
10
void sbfree (struct sbuf * sb )
11
11
{
12
- free (sb -> sb_data );
12
+ g_free (sb -> sb_data );
13
13
}
14
14
15
- bool sbdrop (struct sbuf * sb , int num )
15
+ bool sbdrop (struct sbuf * sb , size_t num )
16
16
{
17
17
int limit = sb -> sb_datalen / 2 ;
18
18
19
- /*
20
- * We can only drop how much we have
21
- * This should never succeed
22
- */
19
+ g_warn_if_fail (num <= sb -> sb_cc );
23
20
if (num > sb -> sb_cc )
24
21
num = sb -> sb_cc ;
22
+
25
23
sb -> sb_cc -= num ;
26
24
sb -> sb_rptr += num ;
27
25
if (sb -> sb_rptr >= sb -> sb_data + sb -> sb_datalen )
@@ -34,30 +32,11 @@ bool sbdrop(struct sbuf *sb, int num)
34
32
return false;
35
33
}
36
34
37
- void sbreserve (struct sbuf * sb , int size )
35
+ void sbreserve (struct sbuf * sb , size_t size )
38
36
{
39
- if (sb -> sb_data ) {
40
- /* Already alloced, realloc if necessary */
41
- if (sb -> sb_datalen != size ) {
42
- char * new = realloc (sb -> sb_data , size );
43
- sb -> sb_cc = 0 ;
44
- if (new ) {
45
- sb -> sb_data = sb -> sb_wptr = sb -> sb_rptr = new ;
46
- sb -> sb_datalen = size ;
47
- } else {
48
- free (sb -> sb_data );
49
- sb -> sb_data = sb -> sb_wptr = sb -> sb_rptr = NULL ;
50
- sb -> sb_datalen = 0 ;
51
- }
52
- }
53
- } else {
54
- sb -> sb_wptr = sb -> sb_rptr = sb -> sb_data = (char * )malloc (size );
55
- sb -> sb_cc = 0 ;
56
- if (sb -> sb_wptr )
57
- sb -> sb_datalen = size ;
58
- else
59
- sb -> sb_datalen = 0 ;
60
- }
37
+ sb -> sb_wptr = sb -> sb_rptr = sb -> sb_data = g_realloc (sb -> sb_data , size );
38
+ sb -> sb_cc = 0 ;
39
+ sb -> sb_datalen = size ;
61
40
}
62
41
63
42
/*
@@ -164,17 +143,17 @@ static void sbappendsb(struct sbuf *sb, struct mbuf *m)
164
143
* Don't update the sbuf rptr, this will be
165
144
* done in sbdrop when the data is acked
166
145
*/
167
- void sbcopy (struct sbuf * sb , int off , int len , char * to )
146
+ void sbcopy (struct sbuf * sb , size_t off , size_t len , char * to )
168
147
{
169
148
char * from ;
170
149
150
+ g_assert (len + off <= sb -> sb_cc );
151
+
171
152
from = sb -> sb_rptr + off ;
172
153
if (from >= sb -> sb_data + sb -> sb_datalen )
173
154
from -= sb -> sb_datalen ;
174
155
175
156
if (from < sb -> sb_wptr ) {
176
- if (len > sb -> sb_cc )
177
- len = sb -> sb_cc ;
178
157
memcpy (to , from , len );
179
158
} else {
180
159
/* re-use off */
0 commit comments