GeneralPurpose-UninitializedVaListOrMissingVaEndΒΆ
Use of va_list without a va_start or a va_start without va_end
Required inputs: IR
va_arg must properly initialize the va_list with va_start and clean
up with va_end. If va_start is missing, va_arg operates on uninitialized data, causing undefined
behavior. If va_end is not called, resources may leak. Every va_start must have a matching va_end
in all execution paths.
Bad code (missing va_start):
void print_values(const char* fmt, ...) {
va_list args;
// ERROR: va_arg without va_start
int value = va_arg(args, int);
}
Bad code (missing va_end):
void print_values(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
int value = va_arg(args, int);
// ERROR: va_end missing
}
Good code (proper va_start/va_end):
void print_values(const char* fmt, ...) {
va_list args;
va_start(args, fmt); // OK: initialize
int value = va_arg(args, int);
va_end(args); // OK: cleanup
}
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
va_arg_missing_start |
Call requires first a call to va_start. |
None |
False |
va_arg_start_missing_end |
Call requires a call to va_end. |
None |
False |
Options
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
This rule has no individual options.