여기에 내가 이런 식으로 ... 다른 함수에서이 전화 드렸습니다에 fwrite는
void openPageFile(filehandle *fHandle) {
FILE *fptr;
opening file
initialise fields in fHandle
fseek(fptr, 0L, SEEK_SET);
fwrite(fHandle, PAGE_SIZE, 1, fptr);
}
... 내가 기능을 가지고 ... 내 코드의
void test(){
filehandle fHandle;
openPageFile(&fHandle);
}
및 fhandle 구조체는 ...
typedef struct FileHandle {
char *fileName;
//some other fields
} fileHandle;
이렇게하면 결과가 달라집니다.
Windows 시스템에서는 작동합니다. 우분투 12.04에 을 입력하면 오류가 발생하지 않지만 데이터를 쓰지는 않습니다. 우분투 13.10에서 을 실행하면 fwrite 행에 seg fault가 발생합니다.
valgrind를 사용하여 메모리 누수를 확인했으며 여기에 내 스택 추적이 있습니다. 세드릭 내가 정확히 알아낼 수 없습니다
Process terminating with default action of signal 11 (SIGSEGV)
==3118== Access not within mapped region at address 0x4051EB
==3118== at 0x4EB44A0: __GI_mempcpy (memcpy.S:166)
==3118== by 0x4EA4EFD: _IO_default_xsputn (genops.c:463)
==3118== by 0x4EA3611: [email protected]@GLIBC_2.2.5 (fileops.c:1356)
==3118== by 0x4E9973C: fwrite (iofwrite.c:43)
...
PAGE_SIZE 란 무엇입니까? FileHandle보다 크면 그 이유가 있습니다. – immibis
4096이면 충분합니다. – user3231170
자, 문제가 있습니다. fHandle에서 시작하여 4096 바이트를 쓰려고 시도하지만 4096 바이트를 쓰지 못할 수도 있습니다. – immibis