On Wed, 15 Oct 2025, Osama Abdelkader wrote:

> Passing a va_list to a variadic function like printf() instead of its
> v-variant (vprintf()) is a common programming error that can lead to
> undefined behavior. This adds a warning to detect such cases.
> 
> The warning uses a multi-tiered detection approach:
> 1. First tries the canonical is_va_list_type() function
> 2. Falls back to exact name matching for typedef'd va_list from stdarg.h
> 3. Handles array-to-pointer decay by checking the pointed-to type
> 4. Uses exact string comparison against known system va_list type names
>    to avoid false positives with user-defined types
> 
> The warning message is intentionally generic to work with any function
> that has a format attribute, whether standard library functions or
> user-defined functions.
> 
>       PR c/61898
> gcc/c-family/ChangeLog:
> 
>       * c-format.cc: Include tree-sra.h for is_va_list_type.
>       (check_format_info): Add detection and warning for va_list
>       arguments passed to variadic functions.
> 
> gcc/testsuite/ChangeLog:
> 
>       * gcc.dg/format/pr61898.c: New test.

This is OK.  (I suspect we may end up making further refinements to the 
logic in future.)

-- 
Joseph S. Myers
[email protected]

Reply via email to