array out of bounds

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

array out of bounds

733 Views
satya123
Contributor I

Hi all,

 

i am trying to fix an issue and working with S12x microcontroller with codewarrior IDE where the functionality of the system works in a random manner. I found the following mistake in the code

 

unsigned char array1[32];

unsigned char array2[23];

 

for(i=0;i<=32;i++)

array1[i] =0;

 

now array1[32] is initialized with 0 which is not available. My question is since array2 is declared just below array1 will that be overwritten. From the map file can i know the address of the array1 and see how it is affecting. Can someone explain how the system in these situations.

 

Thanks and regards,

Satya

Labels (1)
Tags (4)
0 Kudos
2 Replies

671 Views
TICS_Fiona
NXP Employee
NXP Employee

By default, the compiler will generate a warning to remind user for this overwritten. If user ignore it, the application will run out of expect. Usually, it will overwritten the data next to array1[] (for your case, it should be array2).  User should avoid such overwritten in his coding.

0 Kudos

671 Views
Wlodek_D_
Senior Contributor II

Hello,

Thank you for your post, however please consider moving it to the right community place (e.g. CodeWarrior Development Tools ) to get it visible for active members.

For details please see general advice Where to post a Discussion?

Thank you for using Freescale Community.

0 Kudos