if(bio->wh == bio->wbuf.d)
bio->wh = bio->wbuf.d = 0;
if(bio->wbuf.d == bio->wbuf.s) {
- if(bio->wh > 0)
+ if(bio->wh > 0) {
memmove(bio->wbuf.b, bio->wbuf.b + bio->wh, bio->wbuf.d -= bio->wh);
+ bio->wh = 0;
+ }
}
ret = min(len, bio->wbuf.s - bio->wbuf.d);
memcpy(bio->wbuf.b + bio->wbuf.d, data, ret);
bio->wbuf.d += ret;
- if((bioflushsome(bio) < 0) && (ret == 0))
- return(-1);
+ if(bioflushsome(bio) < 0) {
+ if(ret == 0)
+ return(-1);
+ if(ret < bio->wbuf.d - bio->wh) { /* Should never be false */
+ bio->wbuf.d -= ret;
+ return(-1);
+ }
+ }
return(ret);
}