[all-commits] [llvm/llvm-project] e10b18: [-Wunsafe-buffer-usage] Support safe patterns of "...

Ziqing Luo via All-commits all-commits at lists.llvm.org
Tue Jul 29 20:57:25 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e10b182a5fb020f6b69ea95d00fd8590bba7559b
      https://github.com/llvm/llvm-project/commit/e10b182a5fb020f6b69ea95d00fd8590bba7559b
  Author: Ziqing Luo <ziqing at udel.edu>
  Date:   2025-07-30 (Wed, 30 Jul 2025)

  Changed paths:
    M clang/lib/Analysis/UnsafeBufferUsage.cpp
    M clang/test/SemaCXX/warn-unsafe-buffer-usage-libc-functions.cpp

  Log Message:
  -----------
  [-Wunsafe-buffer-usage] Support safe patterns of "%.*s" in printf functions (#145862)

The character buffer passed to a "%.*s" specifier may be safely bound if
the precision is properly specified, even if the buffer does not
guarantee null-termination.
For example,
```
void f(std::span<char> span) {
  printf("%.*s", (int)span.size(), span.data());  // "span.data()" does not guarantee null-termination but is safely bound by "span.size()", so this call is safe
}
```
rdar://154072130



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list