[PATCH] D103426: Clang: Extend format string checking to wprintf/wscanf

Marcus Johnson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 23 20:14:42 PDT 2021


MarcusJohnson91 added inline comments.


================
Comment at: clang/lib/AST/TemplateBase.cpp:77-80
+  const Decl *D = nullptr;
+  if (T->isTypedefNameType()) {
+    D = T->getAs<TypedefType>()->getDecl();
+  }
----------------
aaron.ballman wrote:
> This approach seems fragile for getting access to an AST context. I think `TemplateArgument::print()` should likely be given an `const ASTContext &` parameter instead.
Just switched it out, D was only used for the LangOpts() call anyway, so I just did it directly where it's needed instead of creating a variable


================
Comment at: clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp:791-808
+    
+    StringLiteral::StringKind Kind = FormatString->getKind();
+    
+    if (Kind == StringLiteral::Ascii || Kind == StringLiteral::UTF8) {
+      String = FormatString->getStringAsChar();
+    } else if (Kind == StringLiteral::UTF16) {
+      std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> Convert;
----------------
MarcusJohnson91 wrote:
> cor3ntin wrote:
> > I think this code is present in multiple places in your PR, could it be deduplicated?
> Yup, I've been working on that too; This was actually the first thing I started with.
I've moved this code into StringLiteral::getStrDataAsChar(), so now it does the conversion if needed, and removed the big if/else chain in all the places it was used previously.

Oh, and I made StringLiteral::getStrDataAsChar() public in the StringLiteral and I forwarded it in FormatStringLiteral.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103426/new/

https://reviews.llvm.org/D103426



More information about the cfe-commits mailing list