mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
C++: Fix handling of std::va_list that is used as a function parameter
In the Unix ABI, `std::va_list` is defined as `typedef struct __va_list_tag { ... } va_list[1];`, which means that any `std::va_list` used as a function parameter decays to `struct __va_list_tag*`. Handling this actually made the QL code slightly cleaner. The only tricky bit is that we have to determine what type to use as the actual `va_list` type when loading, storing, or modifying a `std::va_list`. To do this, we look at the type of the argument to the `va_*` macro. A detailed QLDoc comment explains the details.
I added a test case for passing a `va_list` as an argument, and then manipulating that `va_list` in the callee.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -885,6 +885,14 @@ void FuncPtrConversions(int(*pfn)(int), void* p) {
|
||||
pfn = (int(*)(int))p;
|
||||
}
|
||||
|
||||
void VAListUsage(int x, __builtin_va_list args) {
|
||||
__builtin_va_list args2;
|
||||
__builtin_va_copy(args2, args);
|
||||
double d = __builtin_va_arg(args, double);
|
||||
float f = __builtin_va_arg(args, int);
|
||||
__builtin_va_end(args2);
|
||||
}
|
||||
|
||||
void VarArgUsage(int x, ...) {
|
||||
__builtin_va_list args;
|
||||
|
||||
@@ -894,6 +902,7 @@ void VarArgUsage(int x, ...) {
|
||||
double d = __builtin_va_arg(args, double);
|
||||
float f = __builtin_va_arg(args, int);
|
||||
__builtin_va_end(args);
|
||||
VAListUsage(x, args2);
|
||||
__builtin_va_end(args2);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user