• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ OPENSSL_realloc函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中OPENSSL_realloc函数的典型用法代码示例。如果您正苦于以下问题:C++ OPENSSL_realloc函数的具体用法?C++ OPENSSL_realloc怎么用?C++ OPENSSL_realloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了OPENSSL_realloc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: sk_insert

int sk_insert(_STACK *st, void *data, int loc)
{
    char **s;

    if (st == NULL)
        return 0;
    if (st->num_alloc <= st->num + 1) {
        s = OPENSSL_realloc((char *)st->data,
                            (unsigned int)sizeof(char *) * st->num_alloc * 2);
        if (s == NULL)
            return (0);
        st->data = s;
        st->num_alloc *= 2;
    }
    if ((loc >= (int)st->num) || (loc < 0))
        st->data[st->num] = data;
    else {
        int i;
        char **f, **t;

        f = st->data;
        t = &(st->data[1]);
        for (i = st->num; i >= loc; i--)
            t[i] = f[i];

#ifdef undef                    /* no memmove on sunos :-( */
        memmove(&(st->data[loc + 1]),
                &(st->data[loc]), sizeof(char *) * (st->num - loc));
#endif
        st->data[loc] = data;
    }
    st->num++;
    st->sorted = 0;
    return (st->num);
}
开发者ID:IIJ-NetBSD,项目名称:netbsd-src,代码行数:35,代码来源:stack.c


示例2: ERR_add_error_vdata

void ERR_add_error_vdata(int num, va_list args)
{
    int i, n, s;
    char *str, *p, *a;

    s = 80;
    str = OPENSSL_malloc(s + 1);
    if (str == NULL)
        return;
    str[0] = '\0';

    n = 0;
    for (i = 0; i < num; i++) {
        a = va_arg(args, char *);
        if (a == NULL)
            a = "<NULL>";
        n += strlen(a);
        if (n > s) {
            s = n + 20;
            p = OPENSSL_realloc(str, s + 1);
            if (p == NULL) {
                OPENSSL_free(str);
                return;
            }
            str = p;
        }
        OPENSSL_strlcat(str, a, (size_t)s + 1);
    }
    ERR_set_error_data(str, ERR_TXT_MALLOCED | ERR_TXT_STRING);
}
开发者ID:danielctull-forks,项目名称:openssl,代码行数:30,代码来源:err.c


示例3: mime_canon

/* Called by:  clear_sign, extract_certificate, extract_request, main, open_private_key, sign */
char*
mime_canon(const char* s)
{
  char* d;
  char* p;
  int len;
  len = strlen(s);
  p = d = (char*)OPENSSL_malloc(len + len);  /* Reserve spaces for CR's to be inserted. */
  if (!d) GOTO_ERR("no memory?");
  
  /* Scan and copy */

  for (; *s; s++) {
    if (s[0] != '\015' && s[0] != '\012')
      *(p++) = *s; /* pass thru */
    else {
      if (s[0] == '\015' && s[1] == '\012') s++;  /* already CRLF */
      *(p++) = '\015'; *(p++) = '\012';
    }
  }
  *(p++) = '\0';

  /* Shrink the buffer back to actual size (not very likely to fail) */

  return (char*)OPENSSL_realloc(d, (p-d));
err:
  return NULL;
}
开发者ID:gitpan,项目名称:zxid,代码行数:29,代码来源:smimemime.c


示例4: BUF_MEM_grow

int BUF_MEM_grow(BUF_MEM *str, size_t len)
{
    char *ret;
    size_t n;

    if (str->length >= len) {
        str->length = len;
        return (len);
    }
    if (str->max >= len) {
        memset(&str->data[str->length], 0, len - str->length);
        str->length = len;
        return (len);
    }
    /* This limit is sufficient to ensure (len+3)/3*4 < 2**31 */
    if (len > LIMIT_BEFORE_EXPANSION) {
        BUFerr(BUF_F_BUF_MEM_GROW, ERR_R_MALLOC_FAILURE);
        return 0;
    }
    n = (len + 3) / 3 * 4;
    if (str->data == NULL)
        ret = OPENSSL_malloc(n);
    else
        ret = OPENSSL_realloc(str->data, n);
    if (ret == NULL) {
        BUFerr(BUF_F_BUF_MEM_GROW, ERR_R_MALLOC_FAILURE);
        len = 0;
    } else {
        str->data = ret;
        str->max = n;
        memset(&str->data[str->length], 0, len - str->length);
        str->length = len;
    }
    return (len);
}
开发者ID:1Project,项目名称:SafeBoardMessenger,代码行数:35,代码来源:buffer.c


示例5: memcpy

_STACK *sk_dup(_STACK *sk)
{
    _STACK *ret;
    char **s;

    if ((ret = sk_new(sk->comp)) == NULL)
        goto err;
    s = (char **)OPENSSL_realloc((char *)ret->data,
                                 (unsigned int)sizeof(char *) *
                                 sk->num_alloc);
    if (s == NULL)
        goto err;
    ret->data = s;

    ret->num = sk->num;
    memcpy(ret->data, sk->data, sizeof(char *) * sk->num);
    ret->sorted = sk->sorted;
    ret->num_alloc = sk->num_alloc;
    ret->comp = sk->comp;
    return (ret);
 err:
    if (ret)
        sk_free(ret);
    return (NULL);
}
开发者ID:IIJ-NetBSD,项目名称:netbsd-src,代码行数:25,代码来源:stack.c


示例6: BUF_MEM_grow

int BUF_MEM_grow(BUF_MEM *str, size_t len)
	{
	char *ret;
	size_t n;

	if (str->length >= len)
		{
		str->length=len;
		return(len);
		}
	if (str->max >= len)
		{
		memset(&str->data[str->length],0,len-str->length);
		str->length=len;
		return(len);
		}
	n=(len+3)/3*4;
	if (str->data == NULL)
		ret=OPENSSL_malloc(n);
	else
		ret=OPENSSL_realloc(str->data,n);
	if (ret == NULL)
		{
		BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE);
		len=0;
		}
	else
		{
		str->data=ret;
		str->max=n;
		memset(&str->data[str->length],0,len-str->length);
		str->length=len;
		}
	return(len);
	}
开发者ID:CoryXie,项目名称:BarrelfishOS,代码行数:35,代码来源:buffer.c


示例7: append_buf

static int append_buf(char **buf, int *size, const char *s)
{
    if (*buf == NULL) {
        *size = 256;
        *buf = app_malloc(*size, "engine buffer");
        **buf = '\0';
    }

    if (strlen(*buf) + strlen(s) >= (unsigned int)*size) {
        char *tmp;
        *size += 256;
        tmp = OPENSSL_realloc(*buf, *size);
        if (tmp == NULL) {
            OPENSSL_free(*buf);
            *buf = NULL;
            return 0;
        }
        *buf = tmp;
    }

    if (**buf != '\0')
        OPENSSL_strlcat(*buf, ", ", *size);
    OPENSSL_strlcat(*buf, s, *size);

    return 1;
}
开发者ID:Barathrum-Liu,项目名称:openssl,代码行数:26,代码来源:engine.c


示例8: OPENSSL_PUT_ERROR

ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
{
    ASN1_ENUMERATED *ret;
    int len,j;

    if (ai == NULL)
        ret=M_ASN1_ENUMERATED_new();
    else
        ret=ai;
    if (ret == NULL)
    {
        OPENSSL_PUT_ERROR(ASN1, BN_to_ASN1_ENUMERATED, ASN1_R_NESTED_ASN1_ERROR);
        goto err;
    }
    if(BN_is_negative(bn)) ret->type = V_ASN1_NEG_ENUMERATED;
    else ret->type=V_ASN1_ENUMERATED;
    j=BN_num_bits(bn);
    len=((j == 0)?0:((j/8)+1));
    if (ret->length < len+4)
    {
        unsigned char *new_data=OPENSSL_realloc(ret->data, len+4);
        if (!new_data)
        {
            OPENSSL_PUT_ERROR(ASN1, BN_to_ASN1_ENUMERATED, ERR_R_MALLOC_FAILURE);
            goto err;
        }
        ret->data=new_data;
    }

    ret->length=BN_bn2bin(bn,ret->data);
    return(ret);
err:
    if (ret != ai) M_ASN1_ENUMERATED_free(ret);
    return(NULL);
}
开发者ID:RobinWuDev,项目名称:Qt,代码行数:35,代码来源:a_enum.c


示例9: ASN1_STRING_set

int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
	{
	unsigned char *c;
	const char *data=_data;
	if (len < 0)
		{
		if (data == NULL)
			return(0);
		else
			len=strlen(data);
		}
	if ((str->length < len) || (str->data == NULL))
		{
		c=str->data;
		if (c == NULL)
			str->data=OPENSSL_malloc(len+1);
		else
			str->data=OPENSSL_realloc(c,len+1);

		if (str->data == NULL)
			{
			ASN1err(ASN1_F_ASN1_STRING_SET,ERR_R_MALLOC_FAILURE);
			str->data=c;
			return(0);
			}
		}
	str->length=len;
	if (data != NULL)
		{
		memcpy(str->data,data,len);
		/* an allowance for strings :-) */
		str->data[len]='\0';
		}
	return(1);
	}
开发者ID:Gucan,项目名称:h3_lichee,代码行数:35,代码来源:asn1_string.c


示例10: sk_insert

int sk_insert(STACK *st, char *data, int loc)
	{
	char **s;

	if(st == NULL) return 0;
	if (st->num_alloc <= st->num+1)
		{
		s=(char **)OPENSSL_realloc((char *)st->data,
			(unsigned int)sizeof(char *)*st->num_alloc*2);
		if (s == NULL)
			return(0);
		st->data=s;
		st->num_alloc*=2;
		}
	if ((loc >= (int)st->num) || (loc < 0))
		st->data[st->num]=data;
	else
		{
		int i;
		char **f,**t;

		f=(char **)st->data;
		t=(char **)&(st->data[1]);
		for (i=st->num; i>=loc; i--)
			t[i]=f[i];

		st->data[loc]=data;
		}
	st->num++;
	st->sorted=0;
	return(st->num);
	}
开发者ID:Gucan,项目名称:h3_lichee,代码行数:32,代码来源:stk.c


示例11: append_buf

static int append_buf(char **buf, const char *s, int *size, int step)
	{
	int l = strlen(s);

	if (*buf == NULL)
		{
		*size = step;
		*buf = OPENSSL_malloc(*size);
		if (*buf == NULL)
			return 0;
		**buf = '\0';
		}

	if (**buf != '\0')
		l += 2;		/* ", " */

	if (strlen(*buf) + strlen(s) >= (unsigned int)*size)
		{
		*size += step;
		*buf = OPENSSL_realloc(*buf, *size);
		}

	if (*buf == NULL)
		return 0;

	if (**buf != '\0')
		BUF_strlcat(*buf, ", ", *size);
	BUF_strlcat(*buf, s, *size);

	return 1;
	}
开发者ID:oss-forks,项目名称:openssl,代码行数:31,代码来源:engine.c


示例12: sk_insert

int sk_insert(_STACK *st, void *data, int loc)
{
    char **s;

    if (st == NULL)
        return 0;
    if (st->num_alloc <= st->num + 1) {
        s = OPENSSL_realloc((char *)st->data,
                            (unsigned int)sizeof(char *) * st->num_alloc * 2);
        if (s == NULL)
            return (0);
        st->data = s;
        st->num_alloc *= 2;
    }
    if ((loc >= (int)st->num) || (loc < 0))
        st->data[st->num] = data;
    else {
        memmove(&(st->data[loc + 1]),
                &(st->data[loc]), sizeof(char *) * (st->num - loc));
        st->data[loc] = data;
    }
    st->num++;
    st->sorted = 0;
    return (st->num);
}
开发者ID:nicholasmsanford,项目名称:openssl,代码行数:25,代码来源:stack.c


示例13: ERR_add_error_vdata

void ERR_add_error_vdata(int num, va_list args)
{
    int i, n, s;
    char *str, *p, *a;

    s = 80;
    str = OPENSSL_malloc(s + 1);
    if (str == NULL)
        return;
    str[0] = '\0';

    n = 0;
    for (i = 0; i < num; i++) {
        a = va_arg(args, char *);
        /* ignore NULLs, thanks to Bob Beck <[email protected]> */
        if (a != NULL) {
            n += strlen(a);
            if (n > s) {
                s = n + 20;
                p = OPENSSL_realloc(str, s + 1);
                if (p == NULL) {
                    OPENSSL_free(str);
                    return;
                }
                str = p;
            }
            OPENSSL_strlcat(str, a, (size_t)s + 1);
        }
    }
    ERR_set_error_data(str, ERR_TXT_MALLOCED | ERR_TXT_STRING);
}
开发者ID:ZuyingWo,项目名称:openssl,代码行数:31,代码来源:err.c


示例14: ERR_add_error_vdata

void ERR_add_error_vdata(int num, va_list args)
{
    int i, n, s;
    char *str, *p, *a;

    s = 80;
    if ((str = OPENSSL_malloc(s + 1)) == NULL) {
        /* ERRerr(ERR_F_ERR_ADD_ERROR_VDATA, ERR_R_MALLOC_FAILURE); */
        return;
    }
    str[0] = '\0';

    n = 0;
    for (i = 0; i < num; i++) {
        a = va_arg(args, char *);
        if (a == NULL)
            a = "<NULL>";
        n += strlen(a);
        if (n > s) {
            s = n + 20;
            p = OPENSSL_realloc(str, s + 1);
            if (p == NULL) {
                OPENSSL_free(str);
                return;
            }
            str = p;
        }
        OPENSSL_strlcat(str, a, (size_t)s + 1);
    }
    if (!err_set_error_data_int(str, ERR_TXT_MALLOCED | ERR_TXT_STRING))
        OPENSSL_free(str);
}
开发者ID:dgalaxy,项目名称:openssl,代码行数:32,代码来源:err.c


示例15: sk_new

_STACK *sk_dup(const _STACK *sk) {
  _STACK *ret;
  void **s;

  if (sk == NULL) {
    return NULL;
  }

  ret = sk_new(sk->comp);
  if (ret == NULL) {
    goto err;
  }

  s = (void **)OPENSSL_realloc(ret->data, sizeof(void *) * sk->num_alloc);
  if (s == NULL) {
    goto err;
  }
  ret->data = s;

  ret->num = sk->num;
  OPENSSL_memcpy(ret->data, sk->data, sizeof(void *) * sk->num);
  ret->sorted = sk->sorted;
  ret->num_alloc = sk->num_alloc;
  ret->comp = sk->comp;
  return ret;

err:
  sk_free(ret);
  return NULL;
}
开发者ID:AadityaDev,项目名称:AadityaDev.github.io,代码行数:30,代码来源:stack.c


示例16: pkcs11_init_cert

static int pkcs11_init_cert(PKCS11_CTX * ctx, PKCS11_TOKEN * token,
	 CK_SESSION_HANDLE session, CK_OBJECT_HANDLE obj, PKCS11_CERT ** ret)
{
	PKCS11_TOKEN_private *tpriv;
	PKCS11_CERT_private *kpriv;
	PKCS11_CERT *cert, *tmp;
	char label[256], data[2048];
	unsigned char id[256];
	CK_CERTIFICATE_TYPE cert_type;
	size_t size;

	size = sizeof(cert_type);
	if (pkcs11_getattr_var(token, obj, CKA_CERTIFICATE_TYPE, &cert_type, &size))
		return -1;

	/* Ignore any certs we don't understand */
	if (cert_type != CKC_X_509)
		return 0;

	tpriv = PRIVTOKEN(token);
	tmp = (PKCS11_CERT *) OPENSSL_realloc(tpriv->certs,
				(tpriv->ncerts + 1) * sizeof(PKCS11_CERT));
	if (!tmp) {
		free(tpriv->certs);
		tpriv->certs = NULL;
		return -1;
	}
	tpriv->certs = tmp;

	cert = tpriv->certs + tpriv->ncerts++;
	memset(cert, 0, sizeof(*cert));
	cert->_private = kpriv = PKCS11_NEW(PKCS11_CERT_private);
	kpriv->object = obj;
	kpriv->parent = token;

	if (!pkcs11_getattr_s(token, obj, CKA_LABEL, label, sizeof(label)))
		cert->label = BUF_strdup(label);
	size = sizeof(data);
	if (!pkcs11_getattr_var(token, obj, CKA_VALUE, data, &size)) {
		const unsigned char *p = (unsigned char *) data;

		cert->x509 = d2i_X509(NULL, &p, size);
	}
	cert->id_len = sizeof(id);
	if (!pkcs11_getattr_var(token, obj, CKA_ID, id, &cert->id_len)) {
		cert->id = (unsigned char *) malloc(cert->id_len);
		memcpy(cert->id, id, cert->id_len);
	}

	/* Initialize internal information */
	kpriv->id_len = sizeof(kpriv->id);
	if (pkcs11_getattr_var(token, obj, CKA_ID, kpriv->id, &kpriv->id_len))
		kpriv->id_len = 0;

	if (ret)
		*ret = cert;

	return 0;
}
开发者ID:izakp,项目名称:TeleVoton,代码行数:59,代码来源:p11_cert.c


示例17: concat

/* Called by:  attach x9, encrypt1, get_req_attr x3, mime_base64_entity x3, mime_mk_multipart x3, mime_raw_entity x3, sign, smime_mk_multipart_signed x4 */
char*
concat(char* b, const char* s)
{
  if (!(b = (char*)OPENSSL_realloc(b, strlen(b)+strlen(s)+1))) GOTO_ERR("no memory?");
  strcat(b,s);
  return b;
err:
  return NULL;
}
开发者ID:gitpan,项目名称:zxid,代码行数:10,代码来源:smimemime.c


示例18: concatmem

/* Called by:  get_req_attr */
char*
concatmem(char* b, const char* s, int len)
{
  int lb = strlen(b);
  if (!(b = (char*)OPENSSL_realloc(b, lb+len+1))) GOTO_ERR("no memory?");
  memcpy(b+lb, s, len);
  b[lb+len] = '\0';
  return b;
err:
  return NULL;
}
开发者ID:gitpan,项目名称:zxid,代码行数:12,代码来源:smimemime.c


示例19: dev_crypto_md5_update

static int dev_crypto_md5_update(EVP_MD_CTX *ctx, const void *data,
                                 unsigned long len)
{
    MD_DATA *md_data = ctx->md_data;

    if (ctx->flags & EVP_MD_CTX_FLAG_ONESHOT)
        return do_digest(md_data->sess.ses, md_data->md, data, len);

    md_data->data = OPENSSL_realloc(md_data->data, md_data->len + len);
    memcpy(md_data->data + md_data->len, data, len);
    md_data->len += len;

    return 1;
}
开发者ID:1Project,项目名称:SafeBoardMessenger,代码行数:14,代码来源:openbsd_hw.c


示例20: buf_mem_grow

static size_t buf_mem_grow(BUF_MEM *buf, size_t len, char clean) {
  char *new_buf;
  size_t n, alloc_size;

  if (buf->length >= len) {
    buf->length = len;
    return len;
  }
  if (buf->max >= len) {
    memset(&buf->data[buf->length], 0, len - buf->length);
    buf->length = len;
    return len;
  }

  n = len + 3;
  if (n < len) {
    /* overflow */
    OPENSSL_PUT_ERROR(BUF, buf_mem_grow, ERR_R_MALLOC_FAILURE);
    return 0;
  }
  n = n / 3;
  alloc_size = n * 4;
  if (alloc_size / 4 != n) {
    /* overflow */
    OPENSSL_PUT_ERROR(BUF, buf_mem_grow, ERR_R_MALLOC_FAILURE);
    return 0;
  }

  if (buf->data == NULL) {
    new_buf = OPENSSL_malloc(alloc_size);
  } else {
    if (clean) {
      new_buf = OPENSSL_realloc_clean(buf->data, buf->max, alloc_size);
    } else {
      new_buf = OPENSSL_realloc(buf->data, alloc_size);
    }
  }

  if (new_buf == NULL) {
    OPENSSL_PUT_ERROR(BUF, buf_mem_grow, ERR_R_MALLOC_FAILURE);
    len = 0;
  } else {
    buf->data = new_buf;
    buf->max = alloc_size;
    memset(&buf->data[buf->length], 0, len - buf->length);
    buf->length = len;
  }

  return len;
}
开发者ID:HungMingWu,项目名称:libquic,代码行数:50,代码来源:buf.c



注:本文中的OPENSSL_realloc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ OPENSSL_strdup函数代码示例发布时间:2022-05-30
下一篇:
C++ OPENSSL_malloc函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap