[clang] [-Wunsafe-buffer-usage] Add check for custom printf/scanf functions (PR #173096)
Oliver Hunt via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 6 13:26:10 PST 2026
ojhunt wrote:
> > Here's the reduced code:
> > ```
> > enum errc { not_a_directory };
> > namespace detail {
> > struct ErrorHandler {
> > ErrorHandler(char *, int *, int *, int *);
> > __attribute__((__format__(__printf__, 3, 4))) void report(errc, char *);
> > };
> > } // namespace detail
> > using detail::ErrorHandler;
> > int __create_directory_ec, __create_directory_p, __create_directory_attributes;
> > void __create_directory() {
> > ErrorHandler err("", &__create_directory_ec, &__create_directory_p,
> > &__create_directory_attributes);
> > err.report(not_a_directory, "");
> > }
> > ```
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > repro command: `clang++ -Wunsafe-buffer-usage crash.cpp`
>
> Isn't `__attribute__((__format__(__printf__, 3, 4))) void report(errc, char *);` a compilation error by default?
Yup, based on the test case I think the argument count tests might not be considering the `this` parameter.
We can trivially fix the assertion with a bounds check, but this makes me suspicious of the interaction of these attributes with member functions in general
https://github.com/llvm/llvm-project/pull/173096
More information about the cfe-commits
mailing list