2013-10-29 4 views
0

파일입니다. 이미 음악 파일을 변경하는 코드를 개발했지만 코드 커버리지를 높이기 위해 둘 이상의 음악 파일을 사용하려고합니다. 그래서 내 iTunes 보관함을 가로 지르고 파일 경로를 버퍼 나 파일로로드하려고합니다. 어느쪽으로 든 충분할 것이다. 이 코드는 fprintf 함수에서 segfaults가 있습니다.쓰기 출력 (3) 나는 음악 파일을 변이합니다 그들을 iTunes에 피드 파일 fuzzer를 개발하고

#include <stdio.h> 
#include <stdlib.h> 
#include <sys/types.h> 
#include <sys/stat.h> 
#include <sys/time.h> 
#include <errno.h> 
#include <fts.h> 

    int compare (const FTSENT**, const FTSENT**); 

int main(void) 
{ 
FILE * musicPaths; 
musicPaths = fopen("Users/NahNig/music_paths", "wb"); 
char *p1 = "/Users/NahNig/Music/iTunes/iTunes Media/Music"; 
char *p2 = NULL; 
char *path[1]; 
path[0] = p1; 
path[1] = p2; 
FTS* file_system = NULL; 
FTSENT* child = NULL; 
FTSENT* parent = NULL; 

file_system = fts_open(path, FTS_COMFOLLOW | FTS_NOCHDIR, &compare); 

if (NULL != file_system) 
{ 
    while((parent = fts_read(file_system)) != NULL) 
    { 
     child = fts_children(file_system,0); 

     if (errno != 0) 
     { 
      perror("fts_children"); 
     } 

     while ((NULL != child) 
      && (NULL != child->fts_link)) 
     { 
      child = child->fts_link; 
      fprintf(musicPaths, "%s%s\n", child->fts_path, child->fts_name); 
      } 
     } 
     fts_close(file_system); 
    } 

    return 0; 
} 


int compare(const FTSENT** one, const FTSENT** two) 
{ 
return (strcmp((*one)->fts_name, (*two)->fts_name)); 
} 

나는 sscanf와 fprintf를 사용하여 자식을 버퍼에 쓰고 fwrite를 시도하여 파일에 쓰려고 시도했다. 그들 중 누구도 일 해왔다. Google에서 찾은 것도별로 도움이되지 않았으므로 도움을 주시면 대단히 감사하겠습니다.

답변

0

당신은 당신이 /Users/NahNig/music_paths에서 처음 /을 놓친 때문에 NULL입니다 fopen()의 반환 값을 테스트하지 않았다. null 포인터를 사용하면 프로그램이 충돌합니다.