[clang] [clang][Sema] Stop format size estimator upon %p to adapt to linux kernel's extension (PR #65969)

Nick Desaulniers via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 11 09:13:09 PDT 2023


================
@@ -860,6 +860,16 @@ class EstimateSizeFormatHandler
       : Size(std::min(Format.find(0), Format.size()) +
              1 /* null byte always written by sprintf */) {}
 
+  bool ShouldStopOnFormatSpecifier(const analyze_printf::PrintfSpecifier &FS,
+                                   unsigned RemainLen) override {
+    if (FS.getConversionSpecifier().getKind() ==
+        analyze_printf::PrintfConversionSpecifier::pArg) {
+      assert(Size >= RemainLen && "no underflow");
+      Size -= RemainLen;
+      return true;
+    }
+    return false;
----------------
nickdesaulniers wrote:

Might be shorter to invert the condition and return early.

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


More information about the cfe-commits mailing list