| ||||||||
Technical Support Support Resources Product Information | C51: SIDE-EFFECTS OF VPRINTF AND VSPRINTFInformation in this article applies to:
SYMPTOMSMy application uses the vsprintf function as follows:
void test_printf(char *output_buffer, char *fmt, ...) reentrant
{
va_list arg_ptr;
va_start (arg_ptr, fmt); // format string
vsprintf(output_buffer, fmt, arg_ptr);
va_end (arg_ptr);
}
The application seems to work fine on real hardware. However, when I use the µVision Simulator, I receive the following error: *** error 65: access violation: no 'write' permission What is the reason for this? CAUSEThe simulator has very strong access checking including checks for access outside the real variable space. The vsprintf function copies the argument buffer addressed by arg_ptr to a local buffer. When the variables are copied, vsprintf copies a fixed number of bytes (40 in large model and 15 in small and compact models) which may be more than were actually passed. Since your application uses the reentrant stack, it is likely that arg_ptr addresses the top of the reentrant stack and overflows during the copy process. On typical hardware this has no negative effects. However, if you have I/O buffers in the address range that overflows you might have unpredictable results. RESOLUTIONMake sure that arg_ptr does not underflow into non-existing external memory space or I/O address space. MORE INFORMATION
SEE ALSOLast Reviewed: Friday, July 15, 2005 | |||||||
| ||||||||