va_arg reads a type that default argument promotion never passes, which is undefined

tx0/c:va-arg-promoted-typedefaultwarningreliability/api-misusedepth fastbug

What it finds

va_arg(ap, char), short or float: arguments in the ... part are promoted, a char or short to int and a float to double, so they never arrive as the type asked for and the behaviour is undefined. Reading the promoted type and converting it works.

From the rule's source, va_arg_promoted_type.rs.

Example from the rule's tests
#include <stdarg.h> int first_char(int n, ...){  va_list ap;  va_start(ap, n);  int c = va_arg(ap, char);tx0 reports: char arrives promoted to int, so va_arg cannot read it  int d = va_arg(ap, int);  va_end(ap);  return c + d;}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/c:va-arg-promoted-type" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/c:va-arg-promoted-type] reason="..."

tx0 explain tx0/c:va-arg-promoted-type shows the same in the terminal. Found a false positive? Report it.