sprintf in cgi causes unhandled interrupts?

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

sprintf in cgi causes unhandled interrupts?

Jump to solution
1,831 Views
LordMark
Contributor IV

Hi everybody.

 

I'm working on M52250demokit, CW for CF 7.2.1 and MQX 3.6.1.

 

I'm developing a small web server as a test; I have different CGIs. Two of them already use sprintf function to format a string that my web page has to capture. If I use sprintf in another CGi then I get hunandled interrupts from all of my tasks. I can see them from the stdout of _int_install_unexpected_isr(). 

 

I'm also using the MQX_INCLUDE_FLOATING_POINT_IO set to 1, but I haven't used it yet. Any suggestion?

 

Regards,

Marco

0 Kudos
Reply
1 Solution
838 Views
CompilerGuru
NXP Employee
NXP Employee

Is the issue as simple as the sprintf buffer is not big enough?

For a
>sprintf (actual_time_ptr, "%d.%d.%d\n")

the output buffer should be big enough for "12.59.59\n", that's 10 characters if the time variables are in range.

If they are not, the buffer has to be much bigger (37 chars, I think, counting 11 chars per %d). but currently the buffer is only 8 characters big, so depending on the time, it does write behind the end of the buffer.

Is actual_time_ptr a debug thing? I hope so, because after the function returns it keeps on pointing to a stack variable of a no longer existing function. I would set it to NULL on exit, even if it is for debugging only.

 

Daniel

View solution in original post

0 Kudos
Reply
3 Replies
838 Views
LordMark
Contributor IV

I'm still encountering the problem even if I tried to reset the definition of MQX_INCLUDE_FLOATING_POINT_IO to 0. It happens only after activating other interrupts. If I call this CGI with no other interrupts, it goes. So I really can't understand my problem yet.

 

This is my CGI.

 

 

static int cgi_gettime (HTTPD_SESSION_STRUCT *session) { char  actual_time[8], *actual_time_ptr; uint_32  len = 0, hours, minutes, seconds;  actual_time_ptr = &actual_time[0];   hours = (uint_32)rtc_time.hours; minutes = (uint_32)rtc_time.minutes; seconds = (uint_32)rtc_time.seconds; sprintf (actual_time_ptr, "%d.%d.%d\n", hours, minutes, seconds);  httpd_sendstr (session->sock, actual_time);            return session->request.content_len;}

 

This is what I get from serial:

 

 

*** UNHANDLED INTERRUPT ***Vector #: 255  0xffOffset  : 1020  0x3fcTask Id: 0x10004 Td_ptr 0x200084d4 Stack Frame: 0xa009610Interrupt_nesting level: 1   PC: 0xffffffff   SR: 0xffffBenvenuti su Archimede!

 

 

or

 

 

*** UNHANDLED INTERRUPT ***Vector #: 2  0x2Offset  : 8  0x8Task Id: 0x10004 Td_ptr 0x200084d4 Stack Frame: 0x200095f0Interrupt_nesting level: 1   PC: 0x000078ba   SR: 0x2004

 

 

seemingly in random occurrence. Anyway only one unhandled interrupt comes at a time at the execution of "sprintf" causing an overflow in interrupt stack and an unknown error from sprintf function (see capture attached). Other interrupts (RTC and GPT) seem to go on, shell task also keeps goin but obviously RAM is corrupted somewhere and the http_server no longer lets me load my web pages.

 

Regards,

Mark.

 

0 Kudos
Reply
839 Views
CompilerGuru
NXP Employee
NXP Employee

Is the issue as simple as the sprintf buffer is not big enough?

For a
>sprintf (actual_time_ptr, "%d.%d.%d\n")

the output buffer should be big enough for "12.59.59\n", that's 10 characters if the time variables are in range.

If they are not, the buffer has to be much bigger (37 chars, I think, counting 11 chars per %d). but currently the buffer is only 8 characters big, so depending on the time, it does write behind the end of the buffer.

Is actual_time_ptr a debug thing? I hope so, because after the function returns it keeps on pointing to a stack variable of a no longer existing function. I would set it to NULL on exit, even if it is for debugging only.

 

Daniel

0 Kudos
Reply
838 Views
LordMark
Contributor IV

OMG.. I had a wrong count of buffer length.... I hadn't noticed that.

 

The pointer is just for debug. Thanks for suggestion.

0 Kudos
Reply