NEWBIE CODE: Segmentation Fault

From: Khayman (khayman_br@yahoo.com)
Date: 08/15/00


Hi friends. :)
I'm using circle bpl17 with ascii player files and I have made a code to
show the players that had more deaths. But sometimes (not always,
sometimes), I used the kgdb to read the core file and I found Segmentation
Fault error. This is the code (I'll to show the line where the error
occurs):

void mural_vermes(struct char_data * ch)
{
  char buft1[1000];
  char jogador[20];
  int jogadores[10] = {};
  int niveljog=0;
  extern struct player_index_element *player_table;
  int j, i, morte = 0;
  struct char_data *victim=NULL;
  struct char_data *ler=NULL;
  *buft1 = '\0';
 morte = 0;
 niveljog = 99999;
 sprintf(buft1 + strlen(buft1),
"\r\n|========================================|\r\n");
 sprintf(buft1 + strlen(buft1),
"|===========MURAL=DOS=VERMES=============|\r\n");
 sprintf(buft1 + strlen(buft1), "|
|\r\n");
  for (i =0; i < 10; i++){
   for (j = 0; j <= top_of_p_table; j++){
     if((victim=is_playing((player_table +j)->name))) {
       if(GET_MORTES(victim) >= morte && find_verme(GET_IDNUM(victim),
jogadores) == -1){
          if (GET_MORTES(victim) == morte && GET_LEVEL(victim) > niveljog) {
          }
          else {
             strcpy(jogador, GET_NAME(victim));
             morte = GET_MORTES(victim);
             niveljog = GET_LEVEL(victim);
             jogadores[i] = GET_IDNUM(victim);
          }
       }
     }
    else {
        CREATE(ler, struct char_data, 1);
        clear_char(ler);
        CREATE(ler->player_specials, struct player_special_data, 1);
        load_char((player_table + j)->name, ler);
        if(ler->player_specials->saved.mortes >= morte &&
find_verme(ler->char_specials.saved.idnum, jogadores) == -1){
          if(ler->player_specials->saved.mortes == morte &&
ler->player.level > niveljog){
        }
          else {

==>         strcpy(jogador, ler->player.name);  ====================> this
is the line where the error occurs

         morte = ler->player_specials->saved.mortes;
         niveljog = ler->player.level;
         jogadores[i] = ler->char_specials.saved.idnum;
         }
       free_char(ler);
       }
    }
  }
  if (morte > 0)
     sprintf(buft1 + strlen(buft1), "| [%3d] %-20s  %3d morte%s |\r\n",
niveljog, jogador, morte, morte == 1 ? " " : "s");
  morte = 0;
  niveljog = 99999;
 }
 sprintf(buft1 + strlen(buft1), "|
|\r\n");
 sprintf(buft1 + strlen(buft1),
"|========================================|\r\n");
 send_to_char(buft1, ch);
}

Thx, Khayman.


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 04/11/01 PDT