array out of bounds

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

array out of bounds

1,504件の閲覧回数
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,442件の閲覧回数
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,442件の閲覧回数
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 件の賞賛
返信