[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: why my program segmentation fault?



Quoting Star Liu <minxinjianxin@gmail.com>:

I wrote a program to copy the memory content of FFFF0000-FFFFFFFF to a
file, but it says "Segmentation fault", (i use AMD64 lenny, so the
address is long), how could i fix it? thanks!

you should only fclose() if Memory != NULL, so your function would be better off like this:

void CopyMemoryToFile(char* FilePath, long StartAddress, long OffSet)
{
   FILE* Memory;
   Memory=fopen (FilePath, "w");
   if(Memory!=NULL)
   {
      void* Start;
      Start=StartAddress;
      fwrite(Start, 1, OffSet, Memory);
      fclose(Memory);
   }
}





Reply to: