안녕하세요, 저는 파일을 PFS 이미지로 압축해야하는 프로젝트를 진행하고 있습니다. 나는 ANSI C 언어를 사용하는 응용 프로그램을 작성 중이다. 각 파일에 Hexdump 및 다른 속성을 저장하고 내부 변수를 저장합니다.C 메모리 할당 오류
포장 된 파일에 대한 모든 정보가 수집되면 각 파일의 정보가 포함 된 출력 파일을 만들어야합니다.
이 작업을 수행함에 따라 메모리 할당에 문제가 있습니다. 오류를 출력하는 코드는 다음과 같습니다. 루프 위에서 채우고
for (Counter = 0; Counter < PackingCount; Counter ++)
{
PFSEntry Packed;
Packed.HexEquivalent = DumpHex(FileNames[Counter]);
strncpy(Packed.Filename, FileNames[Counter], NAME_BLOCK);
Packed.Offset = OffsetCounter;
OffsetCounter += FileSize;
Packed.FileSize = FileSize;
Packed.Timestamp = 2999606509; // For the Sake of Diffing
Packer[Counter] = Packed;
}
구조
typedef struct
{
char Filename [NAME_BLOCK];
u_int32_t Timestamp;
u_int32_t Offset;
u_int32_t FileSize;
char * HexEquivalent;
} PFSEntry;
아래에 도시되고, 다음과 같이 DumpHex 기능이다
char * DumpHex(char * FileName)
{
FILE * File = FileOpener(FileName, "rb");
printf("%s is of Size %ld\r\n\r\n", FileName, FileSize);
fseek(File, 0L, SEEK_END);
FileSize = ftell(File);
fseek(File, 0L, SEEK_SET);
char * HexArray = malloc(FileSize);
unsigned char Character;
int Counter = 0;
while (Counter < FileSize)
{
Character = fgetc(File);
sprintf(HexArray + Counter, "%c", Character);
Counter++;
}
return HexArray;
}
의 육각 출력을 반환하는 함수 DumpHex, 주어진 파일이 다음 오류를 출력 중입니다.
가 발견 용액에 도움이 될 수 있습니다 응용 프로그램에 추가 된 일부 디버그 정보입니다 (코어 덤프).의 a.out : malloc.c를 : 2,369 : sysmalloc 어설`(old_top == (((mbinptr) (((숯 *) & ((AV) -> 빈 [((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd))))) & & old_size == 0) || ((긴 부호) (old_size는)
= (부호 길이) ((((__ builtin_offsetof (구조체 malloc_chunk, fd_nextsize)) + ((2 * (는 sizeof (size_t로))) - 1)) &을 ~ ((2 * (는 sizeof (size_t로))) - 1))) & & ((old_top) -> &을 0x1 사이즈) & & ((부호 길이) old_end & pagemask) == 0) '실패. 중단 아래
Total Files to Pack 38
Size of Packed Structure 80
Packing File 0 of size 9319 Bytes
Packing File 1 of size 1459 Bytes
Packing File 2 of size 844 Bytes
Packing File 3 of size 4396 Bytes
Packing File 4 of size 270250 Bytes
Packing File 5 of size 656800 Bytes
Packing File 6 of size 0 Bytes
Packing File 7 of size 322744 Bytes
Packing File 8 of size 1278114 Bytes
Packing File 9 of size 12473 Bytes
Packing File 10 of size 13791 Bytes
Packing File 11 of size 14158899 Bytes
Packing File 12 of size 343051 Bytes
Packing File 13 of size 599051 Bytes
Packing File 14 of size 505867 Bytes
Packing File 15 of size 10138349 Bytes
Packing File 16 of size 17481 Bytes
Packing File 17 of size 4900 Bytes
Packing File 18 of size 9000 Bytes
Packing File 19 of size 343 Bytes
Packing File 20 of size 6888 Bytes
Packing File 21 of size 13992 Bytes
Packing File 22 of size 916222 Bytes
Packing File 23 of size 2048 Bytes
Packing File 24 of size 7776 Bytes
Packing File 25 of size 13884 Bytes
Packing File 26 of size 10787 Bytes
Packing File 27 of size 12747 Bytes
a.out: malloc.c:2369: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *)
&((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) &&
old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof
(struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 *
(sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end &
pagemask) == 0)' failed.
중단됨 (코어 덤프)
나는 언어에 새로운 오전, 나는 매우 메모리 할당과 무료 방법의 개념을 이해하지 않습니다.
'PFSEntry' 란 무엇입니까? 'PFSEntry.Filename'은 어떤 타입입니까? (그런데, 불행한 동화에 대해 듣고 유감스럽게 생각합니다.) –
PFSEntry.Filename은 Char 파일명으로, – Andrew
'Packed.HexEquivalent = DumpHex (FileNames [Counter]);는'HexEquivalent'가 바늘. 'DumpHex'는 메모리를 동적으로 할당합니까? 아니면 지역 변수에 대한 포인터를 반환하고 있습니까? 아니면 정적 버퍼로? 또는 ... 음, 어쩌면 당신은 그것을 보여 주어야합니다. 그리고 당신의 질문은 정확히 무엇입니까? "메모리 할당에 문제가 있습니까?"라는 것은 정확히 무엇을 의미합니까? –