[clang] Warning Libc functions (PR #101583)

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 13 15:16:38 PDT 2024


================
@@ -483,6 +483,34 @@ bool clang::analyze_format_string::ParseFormatStringHasSArg(const char *I,
   return false;
 }
 
+unsigned clang::analyze_format_string::ParseFormatStringFirstSArgIndex(
+    const char *&I, const char *E, unsigned ArgIndex, const LangOptions &LO,
+    const TargetInfo &Target) {
+  unsigned argIndex = ArgIndex;
+
+  // Keep looking for a %s format specifier until we have exhausted the string.
+  FormatStringHandler H;
+  while (I != E) {
+    const PrintfSpecifierResult &FSR =
+        ParsePrintfSpecifier(H, I, E, argIndex, LO, Target, false, false);
+    // Did a fail-stop error of any kind occur when parsing the specifier?
+    // If so, don't do any more processing.
+    if (FSR.shouldStop())
----------------
haoNoQ wrote:

Is this any easier than simply overriding `HandlePrintfSpecifier()` and `HandleScanfSpecifier()` in `FormatStringHandler` to tell you everything you need in a simple mostly-statically-typed manner?

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


More information about the cfe-commits mailing list