llvm-project
6b6d3374 - [Clang][Sema] Add fortify warnings for memccpy, memset_explicit, and explicit_bzero (#243629)

Commit
7 hours ago
[Clang][Sema] Add fortify warnings for memccpy, memset_explicit, and explicit_bzero (#243629) Teach `-Wfortify-source` in `Sema::checkFortifiedBuiltinMemoryFunction` to diagnose destination buffer overflows/size mismatches for: - `memccpy` (`warn_fortify_source_size_mismatch`, since copying stops if the stop byte is found in the source buffer before reaching `n`, analogous to `strncpy`/`stpncpy`/`strlcpy`) - `memset_explicit` (`LibBuiltin<"string.h">` from C23, `warn_fortify_source_overflow`) - `explicit_bzero` (`GNULibBuiltin<"string.h">`, `warn_fortify_source_overflow`) Also pass explicit builtin parameter indices rather than `TheCall->getNumArgs() - 1` to `Checker.ComputeExplicitObjectSizeArgument` so `__attribute__((diagnose_as_builtin(...)))` wrappers with extra parameters translate the size argument index properly. Part of #142230 Assisted-by: Gemini
Author
Parents
Loading