本文整理汇总了C++中cli_malloc函数的典型用法代码示例。如果您正苦于以下问题:C++ cli_malloc函数的具体用法?C++ cli_malloc怎么用?C++ cli_malloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cli_malloc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: cli_LzmaInitUPX
int cli_LzmaInitUPX(CLI_LZMA **Lp, uint32_t dictsz) {
CLI_LZMA *L = *Lp;
if(!L) {
*Lp = L = cli_calloc(sizeof(*L), 1);
if(!L) {
return LZMA_RESULT_DATA_ERROR;
}
}
L->state.Properties.pb = 2; /* FIXME: these */
L->state.Properties.lp = 0; /* values may */
L->state.Properties.lc = 3; /* not be static */
L->state.Properties.DictionarySize = dictsz;
if (!(L->state.Probs = (CProb *)cli_malloc(LzmaGetNumProbs(&L->state.Properties) * sizeof(CProb))))
return LZMA_RESULT_DATA_ERROR;
if (!(L->state.Dictionary = (unsigned char *)cli_malloc(L->state.Properties.DictionarySize))) {
free(L->state.Probs);
return LZMA_RESULT_DATA_ERROR;
}
L->initted = 1;
LzmaDecoderInit(&L->state);
return LZMA_RESULT_OK;
}
开发者ID:OPSF,项目名称:uClinux,代码行数:29,代码来源:lzma_iface.c
示例2: textCopy
/* Clone the current object */
static text *
textCopy(const text *t_head)
{
text *first = NULL, *last = NULL;
while(t_head) {
if(first == NULL)
last = first = (text *)cli_malloc(sizeof(text));
else {
last->t_next = (text *)cli_malloc(sizeof(text));
last = last->t_next;
}
if(last == NULL) {
cli_errmsg("textCopy: Unable to allocate memory to clone object\n");
if(first)
textDestroy(first);
return NULL;
}
if(t_head->t_line)
last->t_line = lineLink(t_head->t_line);
else
last->t_line = NULL;
t_head = t_head->t_next;
}
if(first)
last->t_next = NULL;
return first;
}
开发者ID:Jyang772,项目名称:clamav-devel,代码行数:34,代码来源:text.c
示例3: textMove
/*
* Put the contents of the given text at the end of the current object.
* The given text emptied; it can be used again if needed, though be warned that
* it will have an empty line at the start.
*/
text *
textMove(text *t_head, text *t)
{
text *ret;
if(t_head == NULL) {
if(t == NULL) {
cli_errmsg("textMove fails sanity check\n");
return NULL;
}
t_head = (text *)cli_malloc(sizeof(text));
if(t_head == NULL) {
cli_errmsg("textMove: Unable to allocate memory for head\n");
return NULL;
}
t_head->t_line = t->t_line;
t_head->t_next = t->t_next;
t->t_line = NULL;
t->t_next = NULL;
return t_head;
}
if(t == NULL)
return t_head;
ret = t_head;
while(t_head->t_next)
t_head = t_head->t_next;
/*
* Move the first line manually so that the caller is left clean but
* empty, the rest is moved by a simple pointer reassignment
*/
t_head->t_next = (text *)cli_malloc(sizeof(text));
if(t_head->t_next == NULL) {
cli_errmsg("textMove: Unable to allocate memory for head->next\n");
return NULL;
}
t_head = t_head->t_next;
assert(t_head != NULL);
if(t->t_line) {
t_head->t_line = t->t_line;
t->t_line = NULL;
} else
t_head->t_line = NULL;
t_head->t_next = t->t_next;
t->t_next = NULL;
return ret;
}
开发者ID:Jyang772,项目名称:clamav-devel,代码行数:59,代码来源:text.c
示例4: cli_bm_initoff
int cli_bm_initoff(const struct cli_matcher *root, struct cli_bm_off *data, const struct cli_target_info *info)
{
int ret;
unsigned int i;
struct cli_bm_patt *patt;
if(!root->bm_patterns) {
data->offtab = data->offset = NULL;
data->cnt = data->pos = 0;
return CL_SUCCESS;
}
data->cnt = data->pos = 0;
data->offtab = (uint32_t *) cli_malloc(root->bm_patterns * sizeof(uint32_t));
if(!data->offtab) {
cli_errmsg("cli_bm_initoff: Can't allocate memory for data->offtab\n");
return CL_EMEM;
}
data->offset = (uint32_t *) cli_malloc(root->bm_patterns * sizeof(uint32_t));
if(!data->offset) {
cli_errmsg("cli_bm_initoff: Can't allocate memory for data->offset\n");
free(data->offtab);
return CL_EMEM;
}
for(i = 0; i < root->bm_patterns; i++) {
patt = root->bm_pattab[i];
if(patt->offdata[0] == CLI_OFF_ABSOLUTE) {
data->offtab[data->cnt] = patt->offset_min + patt->prefix_length;
if(data->offtab[data->cnt] >= info->fsize)
continue;
data->cnt++;
} else if((ret = cli_caloff(NULL, info, root->type, patt->offdata, &data->offset[patt->offset_min], NULL))) {
cli_errmsg("cli_bm_initoff: Can't calculate relative offset in signature for %s\n", patt->virname);
free(data->offtab);
free(data->offset);
return ret;
} else if((data->offset[patt->offset_min] != CLI_OFF_NONE) && (data->offset[patt->offset_min] + patt->length <= info->fsize)) {
if(!data->cnt || (data->offset[patt->offset_min] + patt->prefix_length != data->offtab[data->cnt - 1])) {
data->offtab[data->cnt] = data->offset[patt->offset_min] + patt->prefix_length;
if(data->offtab[data->cnt] >= info->fsize)
continue;
data->cnt++;
}
}
}
cli_qsort(data->offtab, data->cnt, sizeof(uint32_t), NULL);
return CL_SUCCESS;
}
开发者ID:LZ-SecurityTeam,项目名称:clamav-devel,代码行数:50,代码来源:matcher-bm.c
示例5: malloc
cli_ctx *convenience_ctx(int fd) {
cli_ctx *ctx;
struct cl_engine *engine;
ctx = malloc(sizeof(*ctx));
if(!ctx){
printf("ctx malloc failed\n");
return NULL;
}
ctx->engine = engine = cl_engine_new();
if(!(ctx->engine)){
printf("engine malloc failed\n");
free(ctx);
return NULL;
}
ctx->fmap = cli_malloc(sizeof(struct F_MAP *));
if(!(ctx->fmap)){
printf("fmap malloc failed\n");
free(engine);
free(ctx);
return NULL;
}
if(!(*ctx->fmap = fmap(fd, 0, 0))){
printf("fmap failed\n");
free(ctx->fmap);
free(engine);
free(ctx);
return NULL;
}
return ctx;
}
开发者ID:badania,项目名称:clamav-devel,代码行数:34,代码来源:vba.c
示例6: blobGrow
/*
* Return clamav return code
*/
int
blobGrow(blob *b, size_t len)
{
assert(b != NULL);
assert(b->magic == BLOBCLASS);
if(len == 0)
return CL_SUCCESS;
if(b->isClosed) {
/*
* Should be cli_dbgmsg, but I want to see them for now,
* and cli_dbgmsg doesn't support debug levels
*/
cli_warnmsg("Growing closed blob\n");
b->isClosed = 0;
}
if(b->data == NULL) {
assert(b->len == 0);
assert(b->size == 0);
b->data = cli_malloc(len);
if(b->data)
b->size = (off_t)len;
} else {
unsigned char *ptr = cli_realloc(b->data, b->size + len);
if(ptr) {
b->size += (off_t)len;
b->data = ptr;
}
}
return (b->data) ? CL_SUCCESS : CL_EMEM;
}
开发者ID:nsxz,项目名称:clamav-devel,代码行数:38,代码来源:blob.c
示例7: diff_file_mem
void diff_file_mem(int fd, const char *ref, size_t len)
{
char c1,c2;
size_t p, reflen = len;
char *buf = cli_malloc(len);
fail_unless_fmt(!!buf, "unable to malloc buffer: %d", len);
p = read(fd, buf, len);
fail_unless_fmt(p == len, "file is smaller: %lu, expected: %lu", p, len);
p = 0;
while(len > 0) {
c1 = ref[p];
c2 = buf[p];
if(c1 != c2)
break;
p++;
len--;
}
if (len > 0)
fail_unless_fmt(c1 == c2, "file contents mismatch at byte: %lu, was: %c, expected: %c", p, c2, c1);
free(buf);
p = lseek(fd, 0, SEEK_END);
fail_unless_fmt(p == reflen, "trailing garbage, file size: %ld, expected: %ld", p, reflen);
close(fd);
}
开发者ID:CyberIntelMafia,项目名称:clamav-devel,代码行数:25,代码来源:check_clamav.c
示例8: tableInsert
/*
* Returns the value, or -1 for failure
*/
int
tableInsert(table_t *table, const char *key, int value)
{
const int v = tableFind(table, key);
if(v > 0) /* duplicate key */
return (v == value) ? value : -1; /* allow real dups */
assert(value != -1); /* that would confuse us */
if(table->tableHead == NULL)
table->tableLast = table->tableHead = (tableEntry *)cli_malloc(sizeof(tableEntry));
else {
/*
* Re-use deleted items
*/
if(table->flags&TABLE_HAS_DELETED_ENTRIES) {
tableEntry *tableItem;
assert(table->tableHead != NULL);
for(tableItem = table->tableHead; tableItem; tableItem = tableItem->next)
if(tableItem->key == NULL) {
/* This item has been deleted */
tableItem->key = cli_strdup(key);
tableItem->value = value;
return value;
}
table->flags &= ~TABLE_HAS_DELETED_ENTRIES;
}
table->tableLast = table->tableLast->next =
(tableEntry *)cli_malloc(sizeof(tableEntry));
}
if(table->tableLast == NULL) {
cli_dbgmsg("tableInsert: Unable to allocate memory for table\n");
return -1;
}
table->tableLast->next = NULL;
table->tableLast->key = cli_strdup(key);
table->tableLast->value = value;
return value;
}
开发者ID:CyberIntelMafia,项目名称:clamav-devel,代码行数:50,代码来源:table.c
示例9: hashtab_insert
int hashtab_insert(struct hashtable *s,const unsigned char* key,const size_t len,const element_data data)
{
struct element* element;
struct element* deleted_element = NULL;
size_t tries = 1;
size_t idx;
if(!s)
return CL_ENULLARG;
do {
PROFILE_CALC_HASH(s);
idx = hash(key, len, s->capacity);
element = &s->htable[idx];
do {
if(!element->key) {
unsigned char* thekey;
/* element not found, place is empty, insert*/
if(deleted_element) {
/* reuse deleted elements*/
element = deleted_element;
PROFILE_DELETED_REUSE(s, tries);
}
else {
PROFILE_INSERT(s, tries);
}
thekey = cli_malloc(len+1);
if(!thekey)
return CL_EMEM;
strncpy((char*)thekey,(const char*)key,len+1);
element->key = thekey;
element->data = data;
s->used++;
if(s->used > s->maxfill) {
cli_dbgmsg("hashtab.c:Growing hashtable %p, because it has exceeded maxfill, old size:%ld\n",(void*)s,s->capacity);
hashtab_grow(s);
}
return 0;
}
else if(element->key == DELETED_KEY) {
deleted_element = element;
}
else if(strncmp((const char*)key,(const char*)element->key,len)==0) {
PROFILE_DATA_UPDATE(s, tries);
element->data = data;/* key found, update */
return 0;
}
else {
idx = (idx + tries++) % s->capacity;
element = &s->htable[idx];
}
} while (tries <= s->capacity);
/* no free place found*/
PROFILE_HASH_EXHAUSTED(s);
cli_dbgmsg("hashtab.c: Growing hashtable %p, because its full, old size:%ld.\n",(void*)s,s->capacity);
} while( hashtab_grow(s) >= 0 );
cli_warnmsg("hashtab.c: Unable to grow hashtable\n");
return CL_EMEM;
}
开发者ID:5432935,项目名称:crossbridge,代码行数:58,代码来源:libclamav_hashtab.c
示例10: onas_ddd_watch_hierarchy
static int onas_ddd_watch_hierarchy(const char* pathname, size_t len, int fd, uint64_t mask, uint32_t type) {
if (!pathname || fd <= 0 || !type) return CL_ENULLARG;
if (type == (ONAS_IN | ONAS_FAN)) return CL_EARG;
struct onas_hnode *hnode = NULL;
struct onas_element *elem = NULL;
int wd = 0;
if(onas_ht_get(ddd_ht, pathname, len, &elem) != CL_SUCCESS) return CL_EARG;
hnode = elem->data;
if (type & ONAS_IN) {
wd = inotify_add_watch(fd, pathname, (uint32_t) mask);
if (wd < 0) return CL_EARG;
if (wd >= wdlt_len) {
onas_ddd_grow_wdlt();
}
/* Link the hash node to the watch descriptor lookup table */
hnode->wd = wd;
wdlt[wd] = hnode->pathname;
hnode->watched |= ONAS_INWATCH;
} else if (type & ONAS_FAN) {
if(fanotify_mark(fd, FAN_MARK_ADD, mask, AT_FDCWD, hnode->pathname) < 0) return CL_EARG;
hnode->watched |= ONAS_FANWATCH;
} else {
return CL_EARG;
}
struct onas_lnode *curr = hnode->childhead;
while (curr->next != hnode->childtail) {
curr = curr->next;
size_t size = len + strlen(curr->dirname) + 2;
char *child_path = (char *) cli_malloc(size);
if (child_path == NULL)
return CL_EMEM;
if (hnode->pathname[len-1] == '/')
snprintf(child_path, --size, "%s%s", hnode->pathname, curr->dirname);
else
snprintf(child_path, size, "%s/%s", hnode->pathname, curr->dirname);
if(onas_ddd_watch_hierarchy(child_path, strlen(child_path), fd, mask, type)) {
return CL_EARG;
}
free(child_path);
}
return CL_SUCCESS;
}
开发者ID:xiongjungit,项目名称:clamav-devel,代码行数:57,代码来源:onaccess_ddd.c
示例11: cli_jsonstrlen_nojson
int cli_jsonstrlen_nojson(const char* key, const char* s, int len)
{
char *sp = cli_malloc(len+1);
strncpy(sp, s, len);
sp[len] = '\0';
nojson_func("nojson: %s: %s\n", key, sp);
free(sp);
return CL_SUCCESS;
}
开发者ID:nayden,项目名称:clamav-devel,代码行数:11,代码来源:json_api.c
示例12: cli_dbgmsg
void *__lzma_wrap_alloc(void *unused, size_t size) {
if(!size || size > CLI_MAX_ALLOCATION)
return NULL;
unused = unused;
if(!size || size > CLI_MAX_ALLOCATION) {
cli_dbgmsg("lzma_wrap_alloc(): Attempt to allocate %lu bytes.\n", (unsigned long int) size);
return NULL;
}
return cli_malloc(size);
}
开发者ID:eqmcc,项目名称:clamav_decode,代码行数:11,代码来源:lzma_iface.c
示例13: string_assign_dup
/* make a copy of the string between start -> end*/
static int string_assign_dup(struct string* dest,const char* start,const char* end)
{
char* ret = cli_malloc(end-start+1);
if(!ret)
return CL_EMEM;
strncpy(ret,start,end-start);
ret[end-start]='\0';
string_free(dest);
string_init_c(dest, ret);
return CL_SUCCESS;
}
开发者ID:alepharchives,项目名称:clamav-devel,代码行数:13,代码来源:phishcheck.c
示例14: get_unicode_name
static char *
get_unicode_name(const char *name, int size, int big_endian)
{
int i, increment;
char *newname, *ret;
if((name == NULL) || (*name == '\0') || (size <= 0))
return NULL;
newname = (char *)cli_malloc(size * 7 + 1);
if(newname == NULL) {
cli_errmsg("get_unicode_name: Unable to allocate memory for newname\n");
return NULL;
}
if((!big_endian) && (size & 0x1)) {
cli_dbgmsg("get_unicode_name: odd number of bytes %d\n", size);
--size;
}
increment = (big_endian) ? 1 : 2;
ret = newname;
for(i = 0; i < size; i += increment) {
if((!(name[i]&0x80)) && isprint(name[i])) {
*ret++ = tolower(name[i]);
} else {
if((name[i] < 10) && (name[i] >= 0)) {
*ret++ = '_';
*ret++ = (char)(name[i] + '0');
} else {
uint16_t x;
if ((i + 1) >= size)
break;
x = (uint16_t)((name[i] << 8) | name[i + 1]);
*ret++ = '_';
*ret++ = (char)('a'+((x&0xF)));
*ret++ = (char)('a'+((x>>4)&0xF));
*ret++ = (char)('a'+((x>>8)&0xF));
*ret++ = 'a';
*ret++ = 'a';
}
*ret++ = '_';
}
}
*ret = '\0';
/* Saves a lot of memory */
ret = cli_realloc(newname, (ret - newname) + 1);
return ret ? ret : newname;
}
开发者ID:vrtadmin,项目名称:clamav-devel,代码行数:53,代码来源:vba_extract.c
示例15: cli_LzmaInit
int cli_LzmaInit(CLI_LZMA **Lp, uint64_t size_override) {
CLI_LZMA *L = *Lp;
if(!L) {
*Lp = L = cli_calloc(sizeof(*L), 1);
if(!L) {
return CL_EMEM;
}
}
L->initted = 0;
if(size_override) L->usize=size_override;
if (!L->next_in || L->avail_in < LZMA_PROPERTIES_SIZE + 8) return LZMA_RESULT_OK;
if (LzmaDecodeProperties(&L->state.Properties, L->next_in, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK)
return LZMA_RESULT_DATA_ERROR;
L->next_in += LZMA_PROPERTIES_SIZE;
L->avail_in -= LZMA_PROPERTIES_SIZE;
if (!L->usize) {
L->usize=(uint64_t)cli_readint32(L->next_in) + ((uint64_t)cli_readint32(L->next_in+4)<<32);
L->next_in += 8;
L->avail_in -= 8;
}
if (!(L->state.Probs = (CProb *)cli_malloc(LzmaGetNumProbs(&L->state.Properties) * sizeof(CProb))))
return LZMA_RESULT_DATA_ERROR;
if (!(L->state.Dictionary = (unsigned char *)cli_malloc(L->state.Properties.DictionarySize))) {
free(L->state.Probs);
return LZMA_RESULT_DATA_ERROR;
}
L->initted = 1;
LzmaDecoderInit(&L->state);
return LZMA_RESULT_OK;
}
开发者ID:OPSF,项目名称:uClinux,代码行数:39,代码来源:lzma_iface.c
示例16: string_assign_concatenated
/* assigns to @dest the string made from concatenating @prefix with the string between @begin and @end */
static int string_assign_concatenated(struct string* dest, const char* prefix, const char* begin, const char* end)
{
const size_t prefix_len = strlen(prefix);
char* ret = cli_malloc(prefix_len + end - begin + 1);
if(!ret)
return CL_EMEM;
strncpy(ret, prefix, prefix_len);
strncpy(ret+prefix_len, begin, end-begin);
ret[prefix_len+end-begin]='\0';
string_free(dest);
string_init_c(dest, ret);
return CL_SUCCESS;
}
开发者ID:alepharchives,项目名称:clamav-devel,代码行数:14,代码来源:phishcheck.c
示例17: onas_ddd_unwatch_hierarchy
static int onas_ddd_unwatch_hierarchy(const char* pathname, size_t len, int fd, uint32_t type) {
if (!pathname || fd <= 0 || !type) return CL_ENULLARG;
if (type == (ONAS_IN | ONAS_FAN)) return CL_EARG;
struct onas_hnode *hnode = NULL;
struct onas_element *elem = NULL;
int wd = 0;
if(onas_ht_get(ddd_ht, pathname, len, &elem)) return CL_EARG;
hnode = elem->data;
if (type & ONAS_IN) {
wd = hnode->wd;
if(!inotify_rm_watch(fd, wd)) return CL_EARG;
/* Unlink the hash node from the watch descriptor lookup table */
hnode->wd = 0;
wdlt[wd] = NULL;
hnode->watched = ONAS_STOPWATCH;
} else if (type & ONAS_FAN) {
if(fanotify_mark(fd, FAN_MARK_REMOVE, 0, AT_FDCWD, hnode->pathname) < 0) return CL_EARG;
hnode->watched = ONAS_STOPWATCH;
} else {
return CL_EARG;
}
struct onas_lnode *curr = hnode->childhead;
while (curr->next != hnode->childtail) {
curr = curr->next;
size_t size = len + strlen(curr->dirname) + 2;
char *child_path = (char *) cli_malloc(size);
if (child_path == NULL)
return CL_EMEM;
if (hnode->pathname[len-1] == '/')
snprintf(child_path, --size, "%s%s", hnode->pathname, curr->dirname);
else
snprintf(child_path, size, "%s/%s", hnode->pathname, curr->dirname);
onas_ddd_unwatch_hierarchy(child_path, strlen(child_path), fd, type);
free(child_path);
}
return CL_SUCCESS;
}
开发者ID:xiongjungit,项目名称:clamav-devel,代码行数:51,代码来源:onaccess_ddd.c
示例18: string_assign_dup
/* make a copy of the string between start -> end*/
static int string_assign_dup(struct string* dest,const char* start,const char* end)
{
char* ret = cli_malloc(end-start+1);
if(!ret) {
cli_errmsg("Phishcheck: Unable to allocate memory for string_assign_dup\n");
return CL_EMEM;
}
strncpy(ret,start,end-start);
ret[end-start]='\0';
string_free(dest);
string_init_c(dest, ret);
return CL_SUCCESS;
}
开发者ID:rossguide,项目名称:clamav-devel,代码行数:15,代码来源:phishcheck.c
示例19: string_assign_dup
/* make a copy of the string between start -> end*/
static int string_assign_dup(struct string* dest,const char* start,const char* end)
{
char* ret = cli_malloc(end-start+1);
if(!ret)
return CL_EMEM;
strncpy(ret,start,end-start);
ret[end-start]='\0';
string_free(dest);
dest->data=ret;
dest->refcount=1;
dest->ref=NULL;
return CL_SUCCESS;
}
开发者ID:5432935,项目名称:crossbridge,代码行数:15,代码来源:libclamav_phishcheck.c
示例20: str_compose
static char* str_compose(const char* a,const char* b,const char* c)
{
const size_t a_len = strlen(a);
const size_t b_len = strlen(b);
const size_t c_len = strlen(c);
const size_t r_len = a_len+b_len+c_len+1;
char* concated = cli_malloc(r_len);
if(!concated)
return NULL;
strncpy(concated,a,a_len);
strncpy(concated+a_len,b,b_len);
strncpy(concated+a_len+b_len,c,c_len);
concated[r_len-1]='\0';
return concated;
}
开发者ID:5432935,项目名称:crossbridge,代码行数:15,代码来源:libclamav_phishcheck.c
注:本文中的cli_malloc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论