array out of bounds

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

array out of bounds

1,500 次查看
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

标签 (1)
标记 (4)
0 项奖励
回复
2 回复数

1,438 次查看
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 项奖励
回复

1,438 次查看
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 项奖励
回复