Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C Malloc断言_C_Malloc - Fatal编程技术网

C Malloc断言

C Malloc断言,c,malloc,C,Malloc,我在代码中执行malloc时遇到问题 /*function starts*/ if(NULL==(partial_results=(bignum_t**)malloc(sizeof(bignum_t*)*long_op2))){ return NULL; } /*to initialize all the members of the array*/ for(i=0;i<long_op2;i++){ (*(

我在代码中执行malloc时遇到问题

  /*function starts*/

   if(NULL==(partial_results=(bignum_t**)malloc(sizeof(bignum_t*)*long_op2))){
        return NULL;
    }       

    /*to initialize all the members of the array*/
    for(i=0;i<long_op2;i++){
        (*(partial_results+i))=NULL;
    }


    for(i=long_op2-1;i>=0;i--){
        digit2=op2->digits[i]-48;
        count++;
        carry=0;

        if(count==1){
            count2=0;
        }else{
            count2=count-1;
        }

        /*the next malloc is the one that fails*/
        if(NULL==(*(partial_results+(count-1))=(bignum_t*)malloc(sizeof(bignum_t)))){
            return NULL;
        }   

        /*after this the codes continues, but everything from here is ok an it isn't causing any problem*/
对于这一行:

    /*the next malloc is the one that fails*/
    if(NULL==(*(partial_results+(count-1))=(bignum_t*)malloc(sizeof(bignum_t)))){
        return NULL;
    }  
无论如何:


count
需要是
1不要强制执行malloc-如果(NULL=(*(部分结果+(count-1))=(bignum\u t*)malloc(sizeof(bignum\u t))){
试图一次完成太多的工作,`code>如果(count==1){count2=0;}否则{count2=count-1;}我爱死它了!@EdHeal我删除了石膏,但也没用。很抱歉,我没有对该计数发表评论,它从值1开始(因此第一个位置计数-1=0),到值9结束(因此最后一个位置将是8)。我打印出来是为了知道该值。如果我使用[I],则不会,我从8开始,首先我想写0位置,这就是为什么我使用count-1。因此,使用
long_op2-1-i
作为索引值,而不是
count
    /*the next malloc is the one that fails*/
    if(NULL==(*(partial_results+(count-1))=(bignum_t*)malloc(sizeof(bignum_t)))){
        return NULL;
    }  
    partial_results[i]=(bignum_t*)malloc(sizeof(bignum_t));