1

Un bug(illegal instruction) confus
est apparu lorsque,parfois, j'execute la fonction perso(cf la source) // C Source File // Created 29/08/04; 18:53:16 #define MIN_AMS 200//definie la version minimale d'OS nécessaire(ici 2.00) #include <tigcclib.h> #define MESSAGE "Programmé par C.Gallet" #define AUTEUR "Camille Gallet" #define _89  //remplacer par _92 pour avoir 1 version pour 92+ #ifdef _89       //  An idea I copied in Flib source int _ti89; #define _89_92(x, y) (x) //If it's a TI89,then this fonction will return the 2nd argument #else int _ti92plus; int _v200; #define _89_92(x, y) (y) #endif int nbr_colonne=1; short score,difficulte,nb_de_drapeaux; int nbr_ligne=1; int nombre_mines=1; SCR_RECT ECRAN = {{0, 0, _89_92(159,239), _89_92(99,127)}}; //////////////////////////////////////////////////////////////////////////////// void Input(char *buffer/*,unsigned short imax*/)//1 'scanf' amelioré {   SCR_STATE ss;   short key;   unsigned short i = 0;   char save_buffer[10];   strcpy(save_buffer,buffer);   buffer[0] = 0;   SaveScrState (&ss);   do     {       MoveTo (ss.CurX, ss.CurY);       printf ("%s_ ", buffer);       idle();       key = ngetchx ();       if ((key >= '0' && key <= '9') && (i<3)/* && (i<imax)*/)         buffer[i++] = key;       else if (key == KEY_BACKSPACE && i)//efface le caractère         i--;       buffer[i] = 0;     } while (((key != KEY_ENTER) && (key != KEY_ESC)) || (key==KEY_ENTER && i==0));     if ((key == KEY_ESC) || (is_nan(atoi(buffer))))       strcpy(buffer,save_buffer);   MoveTo (ss.CurX, ss.CurY);   printf ("%s   ", buffer); } ////////////////////////////////////////////////////////////////////////////////// void perso (void) {    int option=1,y2=40,buffer;       void *kbq = kbd_queue ();       unsigned char RepetitionFlag,str[5],msg[5];       unsigned short key;       ClrScr();    FontSetSys(F_8x10);        DrawStr(30,10,"PERSONALISER",A_NORMAL);    FontSetSys(F_6x8);    WIN_RECT opRec={25,5,131,25};    DrawClipRect(&opRec,&ECRAN,A_NORMAL | B_DOUBLE | B_CUT);       printf_xy(0,40,">Nb de lignes? %d",nbr_ligne);       printf_xy(0,52," Nb de colonnes? %d",nbr_colonne);       printf_xy(0,64," Nb de mines?");    if (nbr_ligne*nbr_colonne<10)          sprintf(msg,"(max   %d) %d",nbr_ligne*nbr_colonne,nombre_mines);    else if ((nbr_ligne*nbr_colonne>=10) && (nbr_ligne*nbr_colonne<100))           sprintf(msg,"(max  %d) %d",nbr_ligne*nbr_colonne,nombre_mines);    else           sprintf(msg,"(max %d) %d",nbr_ligne*nbr_colonne,nombre_mines);       DrawStr(78,64,msg,A_REPLACE);      do      {     key = 0;     RepetitionFlag = 0;           while (OSdequeue (&key, kbq))// tant qu'aucune touche n'est appuyé           {       idle();                if (OSTimerExpired (APD_TIMER))                {                  off();                   OSTimerRestart(APD_TIMER);// Reset APD Timer to its initial value                }           }           OSTimerRestart(APD_TIMER);     DrawStr(0,y2," ",A_REPLACE);           if(key == KEY_ENTER)                break;        if ((key >= 2345) && (key <= 2392))        {          RepetitionFlag = 1;     // The key was already pressed just before.             key -= 2048;           }        if (key == KEY_UP)  option --;        if (key == KEY_DOWN)  option ++;           if (RepetitionFlag == 1)                    // if key was already pressed just before.        {          if (option <= 1 ) option = 1;          if (option > 3 ) option = 3;           }           else                                                                      // else, ...           {       if (option < 1 ) option = 3;          if (option > 3) option = 1;           }     y2 = 40 + (12 * (option - 1));     DrawStr(0,y2,">",A_REPLACE);     if((option==1)      &&(key!=KEY_ENTER)      &&(key!=KEY_UP)&&(key!=KEY_DOWN)      &&(key!=KEY_OFF)&&(key!=KEY_OFF2))     {        buffer=nbr_ligne;        sprintf(str,"%d",buffer);        MoveTo(90,40);              DrawStr(90,40,"    ",A_REPLACE);              Input(str);              DrawStr(90,40,"    ",A_REPLACE);              DrawStr(90,40,str,A_REPLACE);        nbr_ligne=atoi(str);        if (nbr_ligne>_89_92(22,33) || nbr_ligne==0)//si le nombre est trop grand        {          nbr_ligne=buffer;          sprintf(str,"%d",nbr_ligne);                DrawStr(90,40,"    ",A_REPLACE);                DrawStr(90,40,str,A_REPLACE);        }      }      else if((option==2)            &&(key!=KEY_ENTER)            &&(key!=KEY_UP)&&(key!=KEY_DOWN)            &&(key!=KEY_OFF)&&(key!=KEY_OFF2))      {        buffer=nbr_colonne;        sprintf(str,"%d",buffer);              MoveTo(102,52);              DrawStr(102,52,"    ",A_REPLACE);              Input(str);              DrawStr(102,52,"    ",A_REPLACE);           DrawStr(102,52,str,A_REPLACE);        nbr_colonne = atoi(str);        if (nbr_colonne>_89_92(13,17) || nbr_colonne==0)        {                nbr_colonne=buffer;          sprintf(str,"%d",nbr_colonne);                DrawStr(102,52,"    ",A_REPLACE);                DrawStr(102,52,str,A_REPLACE);        }      }      else if((option==3)                      &&(key!=KEY_ENTER)            &&(key!=KEY_UP)&&(key!=KEY_DOWN)            &&(key!=KEY_OFF)&&(key!=KEY_OFF2))      {        buffer=nombre_mines;        sprintf(str,"%d",buffer);              MoveTo(138,64);              DrawStr(138,64,"    ",A_REPLACE);              Input(str);              DrawStr(138,64,"    ",A_REPLACE);           DrawStr(138,64,str,A_REPLACE);        nombre_mines = atoi(str);        if (nombre_mines>(nbr_ligne*nbr_colonne) || nombre_mines==0)        {          nombre_mines=buffer;          sprintf(str,"%d",nombre_mines);                DrawStr(138,64,"    ",A_REPLACE);                DrawStr(138,64,str,A_REPLACE);        }      }      if (nbr_ligne*nbr_colonne<10)            sprintf(msg,"(max   %d) %d",nbr_ligne*nbr_colonne,nombre_mines);      else if ((nbr_ligne*nbr_colonne>=10) && (nbr_ligne*nbr_colonne<100))             sprintf(msg,"(max  %d) %d",nbr_ligne*nbr_colonne,nombre_mines);      else             sprintf(msg,"(max %d) %d",nbr_ligne*nbr_colonne,nombre_mines);            DrawStr(78,64,msg,A_REPLACE);      if (nombre_mines>(nbr_ligne*nbr_colonne))      {        nombre_mines=nbr_ligne*nbr_colonne;        sprintf(str,"%d",nombre_mines);              DrawStr(138,64,"    ",A_REPLACE);              DrawStr(138,64,str,A_REPLACE);      }         if ((key == KEY_OFF) || (key == KEY_OFF2))            off();   // Turns the calculator off        }while ((key != KEY_ENTER));   ClrScr(); } ////////////////////////////////////////////////////////////////////////////////////// void _main(void) {      short result;   ClrScr();      FontSetSys(F_8x10);      DrawStr(0,0,"Demine V0.6",A_REPLACE);      FontSetSys(F_6x8);      DrawStr(90,2,"by C.Gallet",A_REPLACE);      HANDLE menu2 = PopupNew ("DEMINE", 60);   PopupAddText (menu2, 0, "jouer", 1);   PopupAddText (menu2, 1, "Débutant", 11);   PopupAddText (menu2, 1, "Intermédiaire", 12);   PopupAddText (menu2, 1, "Expert", 13);   PopupAddText (menu2, 1, "Personaliser", 14);   PopupAddText (menu2, -1, "Scores", 2);   PopupAddText (menu2, -1, "A propos", 3);   PopupAddText (menu2, -1, "Quitter", 4);   result = PopupDo (menu2, CENTER, CENTER, 0);   HeapFree (menu2);   if (result == 2)   {           exit(0);   }   if (result == 3)   {           exit(0);   }   ClrScr();   difficulte = 0;   if (result == 4 || !result)   {     exit(0);   }   else if (result == 11)   {     difficulte = 1;        nbr_ligne = 6;        nbr_colonne = 5;        nombre_mines = 3;   }   else if (result == 12)   {     difficulte = 2;     nbr_ligne = _89_92(12,16);     nbr_colonne = _89_92(9,12);        nombre_mines = _89_92(15,19);   }   else if (result == 13)   {     difficulte = 3;     nbr_ligne = _89_92(22,33);     nbr_colonne = _89_92(13,17);     nombre_mines = _89_92(45,60);   }   else if (result == 14)   {        perso();   DlgMessage("menu","aprés perso",BT_CANCEL,BT_NO);   } }
pourriez-vous me dire d'ou vient l'erreur? smile
wartoom.free.fr mon site perso,le portail du divertissement

2

un débordement mémoire surement ?
avatar
« Quand le dernier arbre sera abattu, la dernière rivière empoisonnée, le dernier poisson capturé, alors vous découvrirez que l'argent ne se mange pas. »

3

J'ai juste jeté un coup d'oeuil très rapide. Je suis pas certain que ce soit l'origine de ton problème, mais y'a un truc qui me parait louche:
unsigned char RepetitionFlag,str[5],msg[5];
...
sprintf(msg,"(max   %d) %d",nbr_ligne*nbr_colonne,nombre_mines);

msg est bien trop petit!
avatar

4

ya deja un debordement ici tongue

5

Uther :
J'ai juste jeté un coup d'oeuil très rapide. Je suis pas certain que ce soit l'origine de ton problème, mais y'a un truc qui me parait louche:
unsigned char RepetitionFlag,str[5],msg[5];
...
sprintf(msg,"(max   %d) %d",nbr_ligne*nbr_colonne,nombre_mines);

msg est bien trop petit!

Merci ça marche.
Ah oui je suis bête j'y avais pas penser dehors
gol
wartoom.free.fr mon site perso,le portail du divertissement