Keil Logo

C51: Side-effects of VPRINTF and VSPRINTF


Information in this article applies to:

  • C51 Version 6 and 7

SYMPTOMS

My 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?

CAUSE

The 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.

RESOLUTION

Make sure that arg_ptr does not underflow into non-existing external memory space or I/O address space.

MORE INFORMATION

SEE ALSO


Last Reviewed: Thursday, February 25, 2021


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.