From c070fac05fef41f788b53fe2c1f60519688a40b1 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 27 Oct 2020 07:59:28 +0100 Subject: Teach loplugin:toolslong about curl_easy_getinfo ...see a9266c39cc71c6f23bfcad4ff6d33ccac53b5e52 "loplugin:toolslong (--enable-online-update)" arguing that "the third argument to curl_easy_getinfo(..., CURLINFO_RESPONSE_CODE, ...) must be a pointer to long". Change-Id: I7c542595219d2387cf869953fe40faef2b41b44f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104857 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- compilerplugins/clang/toolslong.cxx | 44 ++++++++++++++++++++++++++++++++++ cui/source/dialogs/AdditionsDialog.cxx | 4 ++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/compilerplugins/clang/toolslong.cxx b/compilerplugins/clang/toolslong.cxx index 1f55fb76d1d6..094087911e6a 100644 --- a/compilerplugins/clang/toolslong.cxx +++ b/compilerplugins/clang/toolslong.cxx @@ -89,6 +89,8 @@ public: bool WalkUpFromFunctionDecl(FunctionDecl const* decl); bool VisitFunctionDecl(FunctionDecl const* decl); + bool VisitCallExpr(CallExpr const* expr); + private: bool rewrite(SourceLocation location); bool isExcludedFile(SourceLocation spellingLocation) const; @@ -511,6 +513,48 @@ bool ToolsLong::VisitFunctionDecl(FunctionDecl const* decl) return true; } +bool ToolsLong::VisitCallExpr(CallExpr const* expr) +{ + if (ignoreLocation(expr)) + { + return true; + } + auto const d1 = expr->getDirectCallee(); + if (d1 == nullptr || !loplugin::DeclCheck(d1).Function("curl_easy_getinfo").GlobalNamespace()) + { + return true; + } + if (expr->getNumArgs() != 3) + { + return true; + } + //TODO: Check expr->getArg(1) is CURLINFO_RESPONSE_CODE + auto const e1 = dyn_cast(expr->getArg(2)->IgnoreParenImpCasts()); + if (e1 == nullptr || e1->getOpcode() != UO_AddrOf) + { + return true; + } + auto const e2 = dyn_cast(e1->getSubExpr()->IgnoreParenImpCasts()); + if (e2 == nullptr) + { + return true; + } + auto const d2 = e2->getDecl(); + if (auto const d3 = dyn_cast(d2)) + { + parmVarDecls_.erase(d3); + } + else if (auto const d4 = dyn_cast(d2)) + { + varDecls_.erase(d4); + } + else if (auto const d5 = dyn_cast(d2)) + { + fieldDecls_.erase(d5); + } + return true; +} + bool ToolsLong::rewrite(SourceLocation location) { if (rewriter != nullptr) diff --git a/cui/source/dialogs/AdditionsDialog.cxx b/cui/source/dialogs/AdditionsDialog.cxx index b8e2cee3febc..cf9a605d5970 100644 --- a/cui/source/dialogs/AdditionsDialog.cxx +++ b/cui/source/dialogs/AdditionsDialog.cxx @@ -117,7 +117,7 @@ std::string curlGet(const OString& rURL) curl_easy_setopt(curl, CURLOPT_WRITEDATA, static_cast(&response_body)); CURLcode cc = curl_easy_perform(curl); - tools::Long http_code = 0; + long http_code = 0; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); if (http_code != 200) @@ -150,7 +150,7 @@ void curlDownload(const OString& rURL, const OUString& sFileURL) curl_easy_setopt(curl, CURLOPT_WRITEDATA, static_cast(&aFile)); CURLcode cc = curl_easy_perform(curl); - tools::Long http_code = 0; + long http_code = 0; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); if (http_code != 200) -- cgit