我的代码运行良好,但是当我用valgrind检查它时,会出现一个错误“是0之后的字节”

时间:2016-07-16 04:00:52

标签: valgrind

这是我的代码(Mask_makeMask函数):

    unsigned char *Mask_makeMask(int width, unsigned char *frame, 
    int *mask, HXecLevel level,int version,int autoMask)
    {
    unsigned char *masked;
    unsigned char *tempmask;

    int temp;
    int maskv[4];
    int maskval = *mask; 


    if(autoMask == 1)
    {
        tempmask = (unsigned char *)malloc(width * width);
        if(tempmask == NULL) return NULL;

        //>>>>>mask 00 process Mask_evaluate is to generate the marsk
        maskv[0] = Mask_evaluate(width,frame);

        //mask 01
        maskMakers[0](width, frame, tempmask);
        maskv[1] = Mask_evaluate(width,tempmask);


        //mask 02
        memset(tempmask,0,sizeof(tempmask));
        maskMakers[1](width, frame, tempmask);
        maskv[2]= Mask_evaluate(width,tempmask);

        //mask 03
        memset(tempmask,0,sizeof(tempmask));
        maskMakers[2](width, frame, tempmask);
        maskv[3] = Mask_evaluate(width,tempmask);
        temp = maskv[0];    
        maskval = 0;
        int i;
        for(i= 1 ;i<4;i++)
        {
        if(temp >= maskv[i])
        {
            maskval = i;
            temp = maskv[i];
        }
        }
    }
    else
    {
        tempmask = (unsigned char *)malloc(width * width);
        if(tempmask == NULL) return NULL;
        if(maskval ==0)
        Mask_evaluate(width,frame);
        else if( maskval >0 && maskval <=3)
        {
        maskMakers[maskval-1](width, frame, tempmask);
        Mask_evaluate(width,tempmask); 
        }
        free(tempmask);
    }

    >masked = (unsigned char *)malloc(width * width);#line 4319 valgrind  
                                                  shows this is an error

    >if(masked == NULL)
    >{
    >   return NULL;
    >} 

    if(maskval ==0 )
    {
        memcpy(masked,frame,width * width);
    }
    else
        maskMakers[maskval-1](width, frame, masked);


    Mask_writeInformation(width, masked, maskval, level,version);
    *mask = maskval;

    if(autoMask == 1)
        free(tempmask);

    return masked;
    }
  

-------我的代码运行良好,但valgrind日志已经破灭了:

    ==2570==  Address 0x5c30429 is 0 bytes after a block of size 729 alloc'd
    ==2570==    at 0x4024F20: malloc (vg_replace_malloc.c:236)
    >==2570==    by 0x410CB07: Mask_makeMask (barhanxin.c:4319)
    ==2570==    by 0x410CF00: HXcode_encodeMask (barhanxin.c:4468)

1。我尝试使用memset(masked,0,width * width)初始化蒙版      当masked不为null时,HXcode_encodeMask调用      Mask_makeMask函数,所以我认为问题是Mask_makeMask,任何人都可以      给我一些如何解决这个问题的建议?

0 个答案:

没有答案