Invalid va_list argument
Variable argument list used after invalidation with va_end
or
not initialized with va_start
or va_copy
Description
This defect occurs
when you use a va_list
variable as an argument
to a function in the vprintf
group but:
You do not initialize the variable previously using
va_start
orva_copy
.You invalidate the variable previously using
va_end
and do not reinitialize it.
For instance, you call the function vsprintf
as vsprintf
(buffer,format, args)
. However, before the function call,
you do not initialize the va_list
variable args
using
either of the following:
va_start(args, paramName)
.paramName
is the last named argument of a variable-argument function. For instance, for the function definitionvoid func(int n, char c, ...) {}
,c
is the last named argument.va_copy(args, anotherList)
.anotherList
is another validva_list
variable.
Risk
The behavior of an uninitialized va_list
argument
is undefined. Calling a function with an uninitialized va_list
argument
can cause stack overflows.
Fix
Before using a va_list
variable as function
argument, initialize it with va_start
or va_copy
.
Clean up the variable using va_end
only after
all uses of the variable.
Examples
Result Information
Group: Programming |
Language: C | C++ |
Default: On for handwritten code, off for generated code |
Command-Line Syntax: INVALID_VA_LIST_ARG |
Impact: High |
Version History
Introduced in R2015b
See Also
Find
defects (-checkers)
| Incorrect data type passed to
va_arg
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)