ARM Technical Support Knowledge Articles

SIDE-EFFECTS OF VPRINTF AND VSPRINTF

Applies to: C51 C Compiler

Answer


Information in this article applies to:


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 uVision 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

Article last edited on: 2005-07-15 10:11:10

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential