[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

Nicolas van Kempen via cfe-commits cfe-commits at lists.llvm.org
Sat Nov 9 16:11:58 PST 2024


================
@@ -0,0 +1,23 @@
+.. title:: clang-tidy - bugprone-undefined-sprintf-overlap
+
+bugprone-undefined-sprintf-overlap
+==================================
+
+Warns if any arguments to the ``sprintf`` family of functions overlap with the
+first argument.
+
+.. code-block:: c++
+
+    char buf[20] = {"hi"};
+    sprintf(buf, "%s%d", buf, 0);
+
+C99 and POSIX.1-2001 states that if copying were to take place between objects
+that overlap, the result is undefined.
----------------
nicovank wrote:

```suggestion
If copying takes place between objects that overlap, the behavior is undefined.
This is stated in the `C23/N3220 standard
<https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf>`_
(sections 7.23.6.5 and 7.23.6.6), as well as the `POSIX.1-2024 standard
<https://pubs.opengroup.org/onlinepubs/9799919799/>`_.
```

Maybe this should also say something about what can happen in practice (unexpected results? segmentation faults?).

https://github.com/llvm/llvm-project/pull/114244


More information about the cfe-commits mailing list