海湾合作委员会:内存归零问题

时间:2014-05-06 06:53:18

标签: c linux

我是gdb调试的新手,请在以下问题中寻求帮助:

1)我有一个程序,其中以下语句将内容从一个中间缓冲区复制到输出缓冲区,然后将其写入图像文件。

*OutputBuf->YPtr  = *CurrPatch->PatchBuffer;

2)CurrPatch-> PatchBuffer是从大小为[1048]的数组中复制的。

3)当我运行程序时,在输出图像中,图像中有一些补丁是黑色的,即该补丁中所有像素的像素值为0。

4)但是当我用put的gdb调试时如果检查

if(* OutputBuf-> YPtr == 0) printf(“OutX =%d OutY =%d * CurrPatch-> PatchBuffer =%d \ n”,OutX,OutY,* CurrPatch-> PatchBuffer); 其中OutX和OUtY是补丁的起点坐标。

在代码中它没有显示* OutputBuf-> YPtr随时变为零。

有关如何调试此问题的任何指针?我试图检查内存泄漏/任何其他内存损坏问题。

main()
{

fun1();

fwrite(OutputBuf->YPtr,1,Temp1,OutPtr); /* writing to image file */

}

fun1()
{   
/*local variables*/
.
.
.
.
size = (CurrPatch->PatchWidth) * (CurrPatch->PatchHeight);
CurrPatch->PatchBuffer = (unsigned char *)malloc(size);
.
.
.

for(l = 0; l < CurrPatch->PatchHeight; l++)
{
  for(m = 0; m < CurrPatch->PatchWidth ;m++ )
  {
        /* Coping from  array   of  static int HighRes1_scale_4[157][1024], k is index*/
    *CurrPatch->PatchBuffer++ = HighRes1_scale_4[k][n++]; 
  }
}

fun2(CurrPatch,OutputBuf);

if(CurrPatch->PatchBuffer != NULL)
{   
    free(CurrPatch->PatchBuffer);
}

} /*fun1 ends*/

fun2(CurrPatch,OutputBuf)
{
/*local variables*/
unsigned char * YPos,*BuffPos;

OutX = CurrPatch->XPos;
OutY = CurrPatch->YPos;

BuffPos = CurrPatch->PatchBuffer;
YPos = OutputBuf->YPtr;

OutputBuf->YPtr = YPos  + (OutputBuf->Width * OutY) + OutX ;

.
.
.
for(l = 0; l < CurrPatch->PatchHeight; l++)
{
  for(m = 0; m < CurrPatch->PatchWidth ;m++ )
  {
    *OutputBuf->YPtr  = *CurrPatch->PatchBuffer;
    if(*OutputBuf->YPtr == 0)
 printf("OutX = %d OutY =%d    *CurrPatch->PatchBuffer= %d\n",  OutX,OutY,*CurrPatch->PatchBuffer);
    OutputBuf->YPtr++;
    CurrPatch->PatchBuffer++;
  }
}


OutputBuf->YPtr = YPos; 
CurrPatch->PatchBuffer = BuffPos;


}

谢谢和问候,

空间

0 个答案:

没有答案