当前位置: 首页>>代码示例>>C++>>正文


C++ safe_emalloc函数代码示例

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


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

示例1: php_password_make_salt

static int php_password_make_salt(size_t length, char *ret) /* {{{ */
{
    size_t raw_length;
    char *buffer;
    char *result;

    if (length > (INT_MAX / 3)) {
        php_error_docref(NULL, E_WARNING, "Length is too large to safely generate");
        return FAILURE;
    }

    raw_length = length * 3 / 4 + 1;

    buffer = (char *) safe_emalloc(raw_length, 1, 1);

    if (FAILURE == php_random_bytes_silent(buffer, raw_length)) {
        php_error_docref(NULL, E_WARNING, "Unable to generate salt");
        efree(buffer);
        return FAILURE;
    }

    result = safe_emalloc(length, 1, 1);
    if (php_password_salt_to64(buffer, raw_length, length, result) == FAILURE) {
        php_error_docref(NULL, E_WARNING, "Generated salt too short");
        efree(buffer);
        efree(result);
        return FAILURE;
    }
    memcpy(ret, result, length);
    efree(result);
    efree(buffer);
    ret[length] = 0;
    return SUCCESS;
}
开发者ID:pinepain,项目名称:php-src,代码行数:34,代码来源:password.c

示例2: reference_levdist

/* {{{ reference_levdist
 * reference implementation, only optimized for memory usage, not speed */
static zend_long reference_levdist(const char *s1, size_t l1, const char *s2, size_t l2, zend_long cost_ins, zend_long cost_rep, zend_long cost_del )
{
	zend_long *p1, *p2, *tmp;
	zend_long c0, c1, c2;
	size_t i1, i2;

	if (l1 == 0) {
		return l2 * cost_ins;
	}
	if (l2 == 0) {
		return l1 * cost_del;
	}

	if ((l1 > LEVENSHTEIN_MAX_LENGTH) || (l2 > LEVENSHTEIN_MAX_LENGTH)) {
		return -1;
	}
	p1 = safe_emalloc((l2 + 1), sizeof(zend_long), 0);
	p2 = safe_emalloc((l2 + 1), sizeof(zend_long), 0);

	for (i2 = 0; i2 <= l2; i2++) {
		p1[i2] = i2 * cost_ins;
	}
	for (i1 = 0; i1 < l1 ; i1++) {
		p2[0] = p1[0] + cost_del;

		for (i2 = 0; i2 < l2; i2++) {
			c0 = p1[i2] + ((s1[i1] == s2[i2]) ? 0 : cost_rep);
			c1 = p1[i2 + 1] + cost_del;
			if (c1 < c0) {
				c0 = c1;
			}
			c2 = p2[i2] + cost_ins;
			if (c2 < c0) {
				c0 = c2;
			}
			p2[i2 + 1] = c0;
		}
		tmp = p1;
		p1 = p2;
		p2 = tmp;
	}
	c0 = p1[l2];

	efree(p1);
	efree(p2);

	return c0;
}
开发者ID:Frgituser,项目名称:php-src,代码行数:50,代码来源:levenshtein.c

示例3: com_call_method

static int com_call_method(zend_string *method, zend_object *object, INTERNAL_FUNCTION_PARAMETERS)
{
	zval *args = NULL;
	php_com_dotnet_object *obj = (php_com_dotnet_object*)object;
	int nargs;
	VARIANT v;
	int ret = FAILURE;

	if (V_VT(&obj->v) != VT_DISPATCH) {
		return FAILURE;
	}

	nargs = ZEND_NUM_ARGS();

	if (nargs) {
		args = (zval *)safe_emalloc(sizeof(zval), nargs, 0);
		zend_get_parameters_array_ex(nargs, args);
	}

	VariantInit(&v);

	if (SUCCESS == php_com_do_invoke_byref(obj, (zend_internal_function*)EX(func), DISPATCH_METHOD|DISPATCH_PROPERTYGET, &v, nargs, args)) {
		php_com_zval_from_variant(return_value, &v, obj->code_page);
		ret = SUCCESS;
		VariantClear(&v);
	}

	if (args) {
		efree(args);
	}

	return ret;
}
开发者ID:PeeHaa,项目名称:php-src,代码行数:33,代码来源:com_handlers.c

示例4: SA_FETCH

zend_object_iterator *php_com_saproxy_iter_get(zend_class_entry *ce, zval *object, int by_ref)
{
	php_com_saproxy *proxy = SA_FETCH(object);
	php_com_saproxy_iter *I;
	int i;

	if (by_ref) {
		zend_throw_error(NULL, "An iterator cannot be used with foreach by reference");
		return NULL;
	}

	I = ecalloc(1, sizeof(*I));
	I->iter.funcs = &saproxy_iter_funcs;
	Z_PTR(I->iter.data) = I;

	I->proxy = proxy;
	ZVAL_COPY(&I->proxy_obj, object);

	I->indices = safe_emalloc(proxy->dimensions + 1, sizeof(LONG), 0);
	for (i = 0; i < proxy->dimensions; i++) {
		convert_to_long(&proxy->indices[i]);
		I->indices[i] = (LONG)Z_LVAL(proxy->indices[i]);
	}

	SafeArrayGetLBound(V_ARRAY(&proxy->obj->v), proxy->dimensions, &I->imin);
	SafeArrayGetUBound(V_ARRAY(&proxy->obj->v), proxy->dimensions, &I->imax);

	I->key = I->imin;

	return &I->iter;
}
开发者ID:KonstantinKuklin,项目名称:php-src,代码行数:31,代码来源:com_saproxy.c

示例5: safe_emalloc

static inline void *accounted_safe_ecalloc(size_t nmemb, size_t alloc_size, size_t offset, ser_context *ctx)
{
	void *ret = safe_emalloc(nmemb, alloc_size, offset);
	memset(ret, '\0', nmemb * alloc_size + offset);
	zend_llist_add_element(&ctx->allocations, &ret);
	return ret;
}
开发者ID:AmesianX,项目名称:php-src,代码行数:7,代码来源:conversions.c

示例6: php_hash_do_hash

static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_bool raw_output_default) /* {{{ */
{
	char *algo, *data, *digest;
	int algo_len, data_len;
	zend_bool raw_output = raw_output_default;
	const php_hash_ops *ops;
	void *context;
	php_stream *stream = NULL;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &algo, &algo_len, &data, &data_len, &raw_output) == FAILURE) {
		return;
	}

	ops = php_hash_fetch_ops(algo, algo_len);
	if (!ops) {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown hashing algorithm: %s", algo);
		RETURN_FALSE;
	}
	if (isfilename) {
		if (CHECK_NULL_PATH(data, data_len)) {
			RETURN_FALSE;
		}
		stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, DEFAULT_CONTEXT);
		if (!stream) {
			/* Stream will report errors opening file */
			RETURN_FALSE;
		}
	}

	context = emalloc(ops->context_size);
	ops->hash_init(context);

	if (isfilename) {
		char buf[1024];
		int n;

		while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
			ops->hash_update(context, (unsigned char *) buf, n);
		}
		php_stream_close(stream);
	} else {
		ops->hash_update(context, (unsigned char *) data, data_len);
	}

	digest = emalloc(ops->digest_size + 1);
	ops->hash_final((unsigned char *) digest, context);
	efree(context);

	if (raw_output) {
		digest[ops->digest_size] = 0;
		RETURN_STRINGL(digest, ops->digest_size, 0);
	} else {
		char *hex_digest = safe_emalloc(ops->digest_size, 2, 1);

		php_hash_bin2hex(hex_digest, (unsigned char *) digest, ops->digest_size);
		hex_digest[2 * ops->digest_size] = 0;
		efree(digest);
		RETURN_STRINGL(hex_digest, 2 * ops->digest_size, 0);
	}
}
开发者ID:31H0B1eV,项目名称:php-src,代码行数:60,代码来源:hash.c

示例7: php_filter_callback

void php_filter_callback(PHP_INPUT_FILTER_PARAM_DECL)
{
	zval retval;
	zval *args;
	int status;

	if (!option_array || !zend_is_callable(option_array, IS_CALLABLE_CHECK_NO_ACCESS, NULL TSRMLS_CC)) {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "First argument is expected to be a valid callback");
		zval_ptr_dtor(value);
		ZVAL_NULL(value);
		return;
	}

	args = safe_emalloc(sizeof(zval), 1, 0);
	ZVAL_COPY(&args[0], value);
	status = call_user_function_ex(EG(function_table), NULL, option_array, &retval, 1, args, 0, NULL TSRMLS_CC);

	if (status == SUCCESS && !Z_ISUNDEF(retval)) {
		zval_ptr_dtor(value);
		ZVAL_COPY_VALUE(value, &retval);
	} else {
		zval_ptr_dtor(value);
		ZVAL_NULL(value);
	}

	zval_ptr_dtor(&args[0]);
	efree(args);
}
开发者ID:KomaBeyond,项目名称:php-src,代码行数:28,代码来源:callback_filter.c

示例8: _timecop_call_mktime

/* {{{ _timecop_call_mktime - timecop_(gm)mktime helper */
static void _timecop_call_mktime(INTERNAL_FUNCTION_PARAMETERS, const char *mktime_function_name, const char *date_function_name)
{
	zval *params;
	uint32_t param_count;

	int i;

	param_count = MAX(ZEND_NUM_ARGS(), MKTIME_NUM_ARGS);
	params = (zval *)safe_emalloc(param_count, sizeof(zval), 0);

	if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), params) == FAILURE) {
		efree(params);
		zend_throw_error(NULL, "Cannot get arguments for calling");
		return;
	}

	param_count = ZEND_NUM_ARGS();
	if (param_count < MKTIME_NUM_ARGS) {
		fill_mktime_params(params, date_function_name, param_count);
		param_count = MKTIME_NUM_ARGS;
	}

	if (ZEND_NUM_ARGS() == 0) {
		php_error_docref(NULL, E_STRICT, "You should be using the time() function instead");
	}

	simple_call_function(mktime_function_name, return_value, param_count, params);

	for (i = ZEND_NUM_ARGS(); i < MKTIME_NUM_ARGS; i++) {
		zval_ptr_dtor(&params[i]);
	}
	efree(params);
}
开发者ID:dreamsxin,项目名称:php-timecop,代码行数:34,代码来源:timecop_php7.c

示例9: PHP_METHOD

/* {{{ proto TimecopDateTime::__construct([string time[, DateTimeZone object]])
   Creates new TimecopDateTime object
*/
PHP_METHOD(TimecopDateTime, __construct)
{
	zval *params;
	zval *obj = getThis();

	params = (zval *)safe_emalloc(ZEND_NUM_ARGS(), sizeof(zval), 0);

	if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), params) == FAILURE) {
		efree(params);
		zend_throw_error(NULL, "Cannot get arguments for TimecopDateTime::__construct");
		RETURN_FALSE;
	}

	/* call original DateTime::__construct() */
	timecop_call_original_constructor(obj, TIMECOP_G(ce_DateTime), params, ZEND_NUM_ARGS());

	if (!EG(exception)) {
		zval *time = NULL, *timezone_obj = NULL;
		if (ZEND_NUM_ARGS() >= 1) {
			time = &params[0];
		}
		if (ZEND_NUM_ARGS() >= 2) {
			timezone_obj = &params[1];
		}
		fix_datetime_timestamp(obj, time, timezone_obj);
	}

	efree(params);
}
开发者ID:dreamsxin,项目名称:php-timecop,代码行数:32,代码来源:timecop_php7.c

示例10: php_filter_callback

void php_filter_callback(PHP_INPUT_FILTER_PARAM_DECL)
{
    zval *retval_ptr;
    zval ***args;
    int status;

    if (!option_array || !zend_is_callable(option_array, IS_CALLABLE_CHECK_NO_ACCESS, NULL TSRMLS_CC)) {
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "First argument is expected to be a valid callback");
        zval_dtor(value);
        Z_TYPE_P(value) = IS_NULL;
        return;
    }

    args = safe_emalloc(sizeof(zval **), 1, 0);
    args[0] = &value;

    status = call_user_function_ex(EG(function_table), NULL, option_array, &retval_ptr, 1, args, 0, NULL TSRMLS_CC);

    if (status == SUCCESS && retval_ptr != NULL) {
        if (retval_ptr != value) {
            zval_dtor(value);
            COPY_PZVAL_TO_ZVAL(*value, retval_ptr);
        } else {
            zval_ptr_dtor(&retval_ptr);
        }
    } else {
        zval_dtor(value);
        Z_TYPE_P(value) = IS_NULL;
    }

    efree(args);
}
开发者ID:browniebraun,项目名称:php-src,代码行数:32,代码来源:callback_filter.c

示例11: strlen

char *str_repeat(const char *input_str, int len)
{
    char *result;
    size_t result_len;

    if (input_str == NULL)
        return NULL;
    if (len <= 0)
        return "";

    result_len = strlen(input_str) * len;
    result = (char *)safe_emalloc(strlen(input_str), len, 1);

    /* Heavy optimization for situations where input string is 1 byte long */
    if (strlen(input_str) == 1) {
        memset(result, *(input_str), len);
    } else {
        char *s, *e, *ee;
        int l=0;
        memcpy(result, input_str, strlen(input_str));
        s = result;
        e = result + strlen(input_str);
        ee = result + result_len;

        while (e<ee) {
            l = (e-s) < (ee-e) ? (e-s) : (ee-e);
            memmove(e, s, l);
            e += l;
        }
    }

    result[result_len] = '\0';
    return result;
}
开发者ID:5up3rc,项目名称:pvt,代码行数:34,代码来源:pvt_helpers.c

示例12: sqlite_handle_quoter

/* NB: doesn't handle binary strings... use prepared stmts for that */
static int sqlite_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype )
{
	*quoted = safe_emalloc(2, unquotedlen, 3);
	sqlite3_snprintf(2*unquotedlen + 3, *quoted, "'%q'", unquoted);
	*quotedlen = strlen(*quoted);
	return 1;
}
开发者ID:LTD-Beget,项目名称:php-src,代码行数:8,代码来源:sqlite_driver.c

示例13: WideCharToMultiByte

PHPAPI char *php_com_olestring_to_string(OLECHAR *olestring, uint *string_len, int codepage TSRMLS_DC)
{
    char *string;
    uint length = 0;
    BOOL ok;

    length = WideCharToMultiByte(codepage, 0, olestring, -1, NULL, 0, NULL, NULL);

    if (length) {
        string = (char*)safe_emalloc(length, sizeof(char), 0);
        length = WideCharToMultiByte(codepage, 0, olestring, -1, string, length, NULL, NULL);
        ok = length > 0;
    } else {
        string = (char*)emalloc(sizeof(char));
        *string = '\0';
        ok = FALSE;
        length = 0;
    }

    if (!ok) {
        char *msg = php_win32_error_to_msg(GetLastError());

        php_error_docref(NULL TSRMLS_CC, E_WARNING,
                         "Could not convert string from unicode: `%s'", msg);

        LocalFree(msg);
    }

    if (string_len) {
        *string_len = length-1;
    }

    return string;
}
开发者ID:Jeffy23,项目名称:php-src,代码行数:34,代码来源:com_olechar.c

示例14: MultiByteToWideChar

PHPAPI OLECHAR *php_com_string_to_olestring(char *string, uint string_len, int codepage TSRMLS_DC)
{
    OLECHAR *olestring = NULL;
    DWORD flags = codepage == CP_UTF8 ? 0 : MB_PRECOMPOSED | MB_ERR_INVALID_CHARS;
    BOOL ok;

    if (string_len == -1) {
        /* determine required length for the buffer (includes NUL terminator) */
        string_len = MultiByteToWideChar(codepage, flags, string, -1, NULL, 0);
    } else {
        /* allow room for NUL terminator */
        string_len++;
    }

    if (string_len > 0) {
        olestring = (OLECHAR*)safe_emalloc(string_len, sizeof(OLECHAR), 0);
        ok = MultiByteToWideChar(codepage, flags, string, string_len, olestring, string_len);
    } else {
        ok = FALSE;
        olestring = (OLECHAR*)emalloc(sizeof(OLECHAR));
        *olestring = 0;
    }

    if (!ok) {
        char *msg = php_win32_error_to_msg(GetLastError());

        php_error_docref(NULL TSRMLS_CC, E_WARNING,
                         "Could not convert string to unicode: `%s'", msg);

        LocalFree(msg);
    }

    return olestring;
}
开发者ID:Jeffy23,项目名称:php-src,代码行数:34,代码来源:com_olechar.c

示例15: _common_callback_no_arg

static int _common_callback_no_arg(void *yajl_ctx, char *type) {
    php_yajl_record *instance = (php_yajl_record *)yajl_ctx;
    zval *return_handle = NULL;
    HashTable *hash;
    zval zType, zArg, *pzType=&zType, *pzArg=&zArg;

    /* Tell PHP where to put the return value */
    php_printf("%p\n", &instance->fci);
    instance->fci.retval_ptr_ptr = &return_handle;

    /* Bundle all the input parameters into an array. */
    instance->fci.params = safe_emalloc(sizeof(zval *), 3, 0);
    instance->fci.param_count = 3;
    instance->fci.params[0] = &instance->php_ctx;
    ZVAL_STRING(pzType, type, 1);
    instance->fci.params[1] = &pzType;
    ZVAL_NULL(pzArg);
    instance->fci.params[2] = &pzArg;

    /* Call the supplied function. */
    zend_call_function(&instance->fci, &instance->fci_cache TSRMLS_CC);

    /* If the allocation succeeded, free the parameter array. */
    if(instance->fci.params) {
        efree(instance->fci.params);
    }

    /* Without this, PHP seems to want to abort trap on me. */
    return 1;
}
开发者ID:sfalvo,项目名称:php-yajl,代码行数:30,代码来源:php-yajl.c


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