AnsweredAssumed Answered

code bug?

Question asked by sebasira on Jan 5, 2012
Latest reply on Jan 9, 2012 by sebasira

Me again!

 

Now with a doubt about a small portion of code... I use cppcheck to find error that compiler can not detect. Well, it acuse this error, but I can't still figrue it out.

 

Here's the code:

byte* const Tabla_CamposDir[]={  DIR_hora,  DIR_cta_cte,  DIR_calle,  DIR_numero,  DIR_ubicacion,  DIR_pasajero,  DIR_demora,  DIR_comentario,  DIR_zona,  DIR_base,  DIR_calle1,  NULL,               // NOTHING  DIR_tarjeta,  DIR_pactado,  DIR_calle2,  DIR_opcional1,  DIR_opcional2,  DIR_opcional3};  void DIRECCION_resetCampos (void){  word i, j;  byte* ptr;    for (i=0; i<(sizeof(Tabla_CamposDir)/2); i++){    ptr = Tabla_CamposDir[i];    // Erase 6 bytes of each buffer (minimum length)    if (ptr != NULL){      for (j=0; j<6; j++){        *(ptr + j) = 0;      }    }  }

 What's inside Tabla_CamposDir are all arrays of at least 7bytes each, I mean:

byte DIR_hora[7];byte DIR_cta_cte[10];

 

The cppcheck says:  Buffer access out-of-bounds: Tabla_CamposDir 

at ptr = Tabla_CamposDir[i];

 

If that's rigth.... How can I solve it? Maybe I'm blind, but I can't figure it out!!

 

 

Thanks to you all!!!

Outcomes