MC9S08QG8 and strange reset while debugging

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

MC9S08QG8 and strange reset while debugging

跳至解决方案
1,589 次查看
neocronos
Contributor III
Hello,

I've been getting a strange reset. Here is when it happens:

From the main I'm calling ejectarea():

Code:
void ejectarea(void){ byte categ;  byte tarea;    categ = concatenar(msgTipRcv[0], msgTipRcv[1]);  tarea = concatenar(msgRecRcv[0], msgRecRcv[1]);...

The program does the first concatenar() but the reset ocurrs in the second.

concatenar() has:

Code:
byte concatenar(char char1, char char2){ byte num12;  char char12[2] = "";     char12[0] = char1;  strcat(&char12, &char2);  num12 = atoi(&char12);

...
 
The reset ocurrs inside strcat() (of string.c) at this part of the code:

Code:
LIBDEF_StringPtr strcat(LIBDEF_StringPtr str_d, LIBDEF_ConstStringPtr str_s) {  LIBDEF_StringPtr sd = str_d;  str_d += strlen(str_d);  while(*str_d++ = *str_s++) {}  return (sd);}

Screenshot
before the reset.

Screenshot after the reset.

It says: "Error: Unable to go into background mode."

Not sure if it is due to the debugger or what but the hardware is not working well and the only way to check for errors is debuggin the code.

Any ideas?

Thanks a lot

标签 (1)
0 项奖励
1 解答
390 次查看
CompilerGuru
NXP Employee
NXP Employee
The usage of the ANSI function strcat is incorrect. The strcat function expects as second parameter a pointer to
a zero terminated string, and here a pointer to a single char is passed instead.
Actually just noted that the first argument is incorrect too Smiley Sad, the result is probably a 3 byte string (2 char's and a 0 byte), but the dest buffer is only 2 bytes.
So should probably be:
Code:
byte concatenar(char char1, char char2){  char char12[3];  char12[0] = char1;  char12[1] = char2;  char12[2] = 0;

 
Using atoi should work, although I would not actually use it due to its lack of
error reporting.

Daniel




在原帖中查看解决方案

0 项奖励
3 回复数
390 次查看
neocronos
Contributor III
Thanks.

Why did I use strcat() in first place? ... :smileytongue:
0 项奖励
391 次查看
CompilerGuru
NXP Employee
NXP Employee
The usage of the ANSI function strcat is incorrect. The strcat function expects as second parameter a pointer to
a zero terminated string, and here a pointer to a single char is passed instead.
Actually just noted that the first argument is incorrect too Smiley Sad, the result is probably a 3 byte string (2 char's and a 0 byte), but the dest buffer is only 2 bytes.
So should probably be:
Code:
byte concatenar(char char1, char char2){  char char12[3];  char12[0] = char1;  char12[1] = char2;  char12[2] = 0;

 
Using atoi should work, although I would not actually use it due to its lack of
error reporting.

Daniel




0 项奖励
390 次查看
JimDon
Senior Contributor III
It would also appear from your before shot that neither char1 or char2 are numbers.

Any time you end with a reset or otherwise in the weeds, think stack crash and look for bad pointer use.


0 项奖励