[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 22:49:57 PDT 2021
MarcusJohnson91 updated this revision to Diff 361414.
MarcusJohnson91 added a comment.
Getting weird crashes all over the place in code I didn't touch, no idea what's going on
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D103426/new/
https://reviews.llvm.org/D103426
Files:
clang/lib/AST/Expr.cpp
clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
Index: clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
@@ -782,8 +782,8 @@
bool BoundsProvided = ArgIndex == DEPR_ONLY;
if (!BoundsProvided) {
- // Currently we only handle (not wide) string literals. It is possible to do
- // better, either by looking at references to const variables, or by doing
+ // Currently we only handle string literals. It is possible to do better
+ // either by looking at references to const variables, or by doing
// real flow analysis.
auto FormatString =
dyn_cast<StringLiteral>(CE->getArg(ArgIndex)->IgnoreParenImpCasts());
Index: clang/lib/AST/Expr.cpp
===================================================================
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -1068,7 +1068,7 @@
}
char *StringLiteral::getStrDataAsChar() {
- std::string Output = "";
+ std::string Output;
char *CString = nullptr;
switch (getKind()) {
@@ -1078,21 +1078,18 @@
return getTrailingObjects<char>();
break;
case StringKind::UTF16: {
- std::string Trail16 = "";
- Trail16 = getTrailingObjects<char>();
- ArrayRef<char> ArrayRef16(Trail16.c_str(), Trail16.length());
- if (llvm::convertUTF16ToUTF8String(ArrayRef16, Output)) {
+ ArrayRef<char> AR(getTrailingObjects<char>(), getByteLength());
+ if (llvm::convertUTF16ToUTF8String(AR, Output)) {
CString = new char[Output.size() + 1]; // +1 for terminating NULL
return CString;
}
break;
}
case StringKind::UTF32: {
- std::string Trail32 = "";
- Trail32 = getTrailingObjects<char>();
- ArrayRef<char> ArrayRef32(Trail32.c_str(), Trail32.length());
- if (llvm::convertUTF32ToUTF8String(ArrayRef32, Output)) {
+ ArrayRef<char> AR(getTrailingObjects<char>(), getByteLength());
+ if (llvm::convertUTF32ToUTF8String(AR, Output)) {
CString = new char[Output.size() + 1];
+ memcpy(CString, Output.c_str(), Output.size());
return CString;
}
break;
@@ -1100,6 +1097,7 @@
case StringKind::Wide: {
if (llvm::convertWideToUTF8(getStringAsWChar(), Output)) {
CString = new char[Output.size() + 1];
+ memcpy(CString, Output.c_str(), Output.size());
return CString;
}
break;
@@ -1108,8 +1106,7 @@
}
const char *StringLiteral::getStrDataAsChar() const {
- const char *ConstString = StringLiteral::getStrDataAsChar();
- return ConstString;
+ return const_cast<const char*>(getStrDataAsChar());
}
StringLiteral::StringLiteral(const ASTContext &Ctx, StringRef Str,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103426.361414.patch
Type: text/x-patch
Size: 2835 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210724/55c60af0/attachment.bin>
More information about the cfe-commits
mailing list