MC9S08QG8 and strange reset while debugging

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

MC9S08QG8 and strange reset while debugging

Jump to solution
1,569 Views
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

Labels (1)
0 Kudos
1 Solution
370 Views
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




View solution in original post

0 Kudos
3 Replies
370 Views
neocronos
Contributor III
Thanks.

Why did I use strcat() in first place? ... :smileytongue:
0 Kudos
371 Views
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 Kudos
370 Views
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 Kudos