array value changing mysteriously


i have  finished ambitious project yet, guys along way.

it inline hockey scoreboard,  2  teamnames of 8 7x5 led arrays, plus whole load of bcd switches scores, penalties, players number, period etc.

there lcd display , buttons set teamnames, or select library of previous names.  thats working fine.

when transmit scoreboard, 22 or 23 byte message sent digit if number command ( 35  or # )  or letter command ( 42 or * )   followed appropriate data.

it starts enough, can set both teamnames, , age group display,  send score update, or set time,  array have stored letters in becomes corrupt, , puts 1 of number data 1 of stored letter data.  gives strangely spelt new name.
here main loop, note show problem arises ,   the buf[2] of number data, somehow gets written buf[21] of letter array.

( monitored free memory , there 372 bytes spare )

i have attached whole code,  messy , needs tidying when can free time.

i think have overlooked stupid usual, spot ?

code: [select]
void loop(){
 
    if ( standby == high ) { 
      blankalpha ();     // clear teamnames
      blanknumbers ();   // clear numbers
    } 
    else  {
      showpenalties (); 
    }
 
 
    checktime ();  //  clock countdown
    swapdisplay();  // switch alpha displays between teamname , age group
 
    uint8_t buf[vw_max_message_len];  //  message
    uint8_t buflen = vw_max_message_len;
    if (vw_get_message(buf, &buflen)) // non-blocking
    {
      serial.println("got: ");  // show on pc debugging
      serial.print(" buflen =   ");
      serial.println( int (buflen));
      ( int h = 0; h <=buflen-1; h++ ) { serial.print(" buffer =   ");
        serial.print(h); serial.print( "  =  "); serial.println( int(buf [h]));
      }
      if ( buf [0] == thispin ) { //  checking device number
        serial.println(" pins match   ");   
        standby = low;  //  wake board
        if ( buf [1] == 42 ) {    //  = * alpha data coming in 
         
          ( int y = 2; y <=22; y++ ) {
            letterstore [y] = buf [y];   // save incoming names buf changing scores etc
            serial.print(" letterstore  "); serial.print(y);
            serial.print("  = ");   serial.println(char ( letterstore [y ]));
          }   //   *****   at point letterstore 21 correct received in buffer unless
          //  number button has been pressed, n case changes new buf[2] value ( key )*****
       
          group = low;  //
          showteamnames ();
         
        } //  end of if ( buf [1] == '*' )
        //***************************************************************************     
        if ( buf [1] == 35 )  // =  # numeric data incoming
        { 
          key = buf [2];   
          serial.print(" key = ");
          serial.println( int (key));   
 
          ( int s = 1; s<= 19; s++ ) {
            rxnumb [s] = buf [s+2] ;     
            serial.print(" rxnumb  ");   
            serial.print(s); 
            serial.print(" = "); 
            serial.println( int ( rxnumb [s]));
            penmint =  rxnumb[7];
            penminu = rxnumb[8];
 
          }
          sortnumbers ();
          refreshpenalties ();
        }  // end of if ( buf [1] == '35' )  //  numeric data incoming
      }
 
      serial.print("freememory()=");
      serial.println(freememory());
    }  //  end of if message
  } // end loop
 

that can happen if write array @ index larger initialised for. there no array boundary checks @ run time can happen if calculating array index use.
you can write own array index boundary checks before storing.


Arduino Forum > Using Arduino > Programming Questions > array value changing mysteriously


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support