2011-11-13 13 views
0

このセグメンテーションフォールトをこの機能で引き続き取得する理由を知ることができません 誰もそれを取り除き、自分のプログラムを動作させる方法について教えてもらえますか?opendir()によるセグメンテーションフォルト?

Lign 33:flux = opendir(path); Lign 98:ret = listdir(env、在庫、在庫、在庫 - >在庫名[在庫 - > i]);

int  listdir(t_env* env, t_stock* stock, t_pos* pos, char* path) 
{ 
     struct dirent* dirinfo; 
     DIR*   flux; 

     init_xy(pos); 
     cl_screen(env); 

     flux = opendir(path); 
     if (flux == NULL) 
       return (1); 
     alloc_mem(stock); 
     stock->i = 0; 
     while ((dirinfo = readdir(flux))) 
     { 
       id_strcpy(stock->stock_name[stock->i], dirinfo->d_name);    
       print_list(env, pos); 
       id_print_str(stock->stock_name[stock->i]); 
       pos->y = pos->y + 1; 
       stock->i = stock->i + 1; 
     } 
     stock->i = stock->i - 1; 
     pos->y = pos->y - 1; 
     pos->ymax = pos->y; 
     closedir(flux); 
     return (0); 
} 

void enter(t_env* env, t_pos* pos, t_stock* stock) 
{ 
     int  ret; 

     (void)pos; 
     cl_screen(env); 
     frame(env); 
     ret = listdir(env, stock, pos, stock->stock_name[stock->i]); 

     ret = 0; 
     if (ret == 1) 
     { 
       free_mem(stock); 
       reset_keypress(); 
       exit(1); 
     } 
     stock->i = 0; 
} 

(gdb) where 
#0 __opendir (name=0x0) at ../sysdeps/unix/opendir.c:86 
#1 0x08048ebb in listdir (env=0xbffff890, stock=0xbffff880, pos=0xbffff86c, path=0x0) at listdir.c:33 
#2 0x080494ad in enter (env=0xbffff890, pos=0xbffff86c, stock=0xbffff880) at run_fct.c:98 
#3 0x0804930a in press (env=0xbffff890, pos=0xbffff86c, stock=0xbffff880, arrows=0xbffff82d "\n") at run_fct.c:51 
#4 0x080491db in run (env=0xbffff890, pos=0xbffff86c, stock=0xbffff880) at run_fct.c:25 
#5 0x08048985 in main (argc=2, argv=0xbffff954) at main.c:35 
+0

opendir()へのパラメータpathはNULLです。 –

答えて

1

あなたのバックトレースはあなたがopendir()からnameパラメータとしてNULLを渡していることを示しています。それはうまくいかないでしょう。 のstockデータ構造が期待どおりに埋められていないようです。特に、stock->stock_name[stock->i]は、opendir()に電話をかけるときにNULLになります。

関連する問題