Addendum to commit #16654.
This commit is contained in:
parent
debf380122
commit
ae1552ee99
@ -94,16 +94,18 @@ BIO *BIO_new_mem_buf(void *buf, int len)
|
|||||||
{
|
{
|
||||||
BIO *ret;
|
BIO *ret;
|
||||||
BUF_MEM *b;
|
BUF_MEM *b;
|
||||||
|
size_t sz;
|
||||||
|
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
BIOerr(BIO_F_BIO_NEW_MEM_BUF,BIO_R_NULL_PARAMETER);
|
BIOerr(BIO_F_BIO_NEW_MEM_BUF,BIO_R_NULL_PARAMETER);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(len == -1) len = strlen(buf);
|
sz = (len<0) ? strlen(buf) : len;
|
||||||
if(!(ret = BIO_new(BIO_s_mem())) ) return NULL;
|
if(!(ret = BIO_new(BIO_s_mem())) ) return NULL;
|
||||||
b = (BUF_MEM *)ret->ptr;
|
b = (BUF_MEM *)ret->ptr;
|
||||||
b->data = buf;
|
b->data = buf;
|
||||||
b->length = len;
|
b->length = sz;
|
||||||
b->max = len;
|
b->max = sz;
|
||||||
ret->flags |= BIO_FLAGS_MEM_RDONLY;
|
ret->flags |= BIO_FLAGS_MEM_RDONLY;
|
||||||
/* Since this is static data retrying wont help */
|
/* Since this is static data retrying wont help */
|
||||||
ret->num = 0;
|
ret->num = 0;
|
||||||
@ -144,22 +146,16 @@ static int mem_read(BIO *b, char *out, int outl)
|
|||||||
{
|
{
|
||||||
int ret= -1;
|
int ret= -1;
|
||||||
BUF_MEM *bm;
|
BUF_MEM *bm;
|
||||||
int i;
|
|
||||||
char *from,*to;
|
|
||||||
|
|
||||||
bm=(BUF_MEM *)b->ptr;
|
bm=(BUF_MEM *)b->ptr;
|
||||||
BIO_clear_retry_flags(b);
|
BIO_clear_retry_flags(b);
|
||||||
ret=(outl > bm->length)?bm->length:outl;
|
ret=(outl >=0 && (size_t)outl > bm->length)?bm->length:outl;
|
||||||
if ((out != NULL) && (ret > 0)) {
|
if ((out != NULL) && (ret > 0)) {
|
||||||
memcpy(out,bm->data,ret);
|
memcpy(out,bm->data,ret);
|
||||||
bm->length-=ret;
|
bm->length-=ret;
|
||||||
/* memmove(&(bm->data[0]),&(bm->data[ret]), bm->length); */
|
|
||||||
if(b->flags & BIO_FLAGS_MEM_RDONLY) bm->data += ret;
|
if(b->flags & BIO_FLAGS_MEM_RDONLY) bm->data += ret;
|
||||||
else {
|
else {
|
||||||
from=(char *)&(bm->data[ret]);
|
memmove(&(bm->data[0]),&(bm->data[ret]),bm->length);
|
||||||
to=(char *)&(bm->data[0]);
|
|
||||||
for (i=0; i<bm->length; i++)
|
|
||||||
to[i]=from[i];
|
|
||||||
}
|
}
|
||||||
} else if (bm->length == 0)
|
} else if (bm->length == 0)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user