From ae03a259fee413faf1540cd81087b3d08fad2c40 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 8 Apr 2017 09:56:09 +0100 Subject: [PATCH] [Minor] Support time_t args in clang plugin --- clang-plugin/printf_check.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/clang-plugin/printf_check.cc b/clang-plugin/printf_check.cc index d8aeee828..f42d487b2 100644 --- a/clang-plugin/printf_check.cc +++ b/clang-plugin/printf_check.cc @@ -60,6 +60,9 @@ namespace rspamd { static bool pid_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx); + static bool time_arg_handler (const Expr *arg, + struct PrintfArgChecker *ctx); + static bool int64_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx); @@ -175,6 +178,9 @@ namespace rspamd { case 'P': return llvm::make_unique (pid_arg_handler, this->pcontext, this->ci); + case 't': + return llvm::make_unique (time_arg_handler, + this->pcontext, this->ci); case 'L': return llvm::make_unique (int64_arg_handler, this->pcontext, this->ci); @@ -627,6 +633,28 @@ namespace rspamd { } } + static bool + time_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx) + { + if (sizeof (time_t) == sizeof (long)) { + return check_builtin_type (arg, + ctx, + {BuiltinType::Kind::ULong, + BuiltinType::Kind::Long}, + "%t"); + } + else if (sizeof (time_t) == sizeof (int)) { + return check_builtin_type (arg, + ctx, + {BuiltinType::Kind::UInt, + BuiltinType::Kind::Int}, + "%t"); + } + else { + assert (0); + } + } + static bool pointer_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx) { -- 2.39.5