You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

printf_check.cc 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. /*-
  2. * Copyright 2016 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <sys/types.h>
  17. #include "printf_check.h"
  18. #include "clang/AST/AST.h"
  19. #include "clang/AST/Expr.h"
  20. #include "clang/AST/ASTConsumer.h"
  21. #include "clang/AST/RecursiveASTVisitor.h"
  22. #include <unordered_map>
  23. #include <unordered_set>
  24. #include <vector>
  25. #include <sstream>
  26. #include <ctype.h>
  27. #include <signal.h>
  28. #include <assert.h>
  29. #include <cstdint>
  30. using namespace clang;
  31. namespace rspamd {
  32. struct PrintfArgChecker;
  33. static bool cstring_arg_handler (const Expr *arg,
  34. struct PrintfArgChecker *ctx);
  35. static bool int_arg_handler (const Expr *arg,
  36. struct PrintfArgChecker *ctx);
  37. static bool long_arg_handler (const Expr *arg,
  38. struct PrintfArgChecker *ctx);
  39. static bool size_arg_handler (const Expr *arg,
  40. struct PrintfArgChecker *ctx);
  41. static bool char_arg_handler (const Expr *arg,
  42. struct PrintfArgChecker *ctx);
  43. static bool double_arg_handler (const Expr *arg,
  44. struct PrintfArgChecker *ctx);
  45. static bool long_double_arg_handler (const Expr *arg,
  46. struct PrintfArgChecker *ctx);
  47. static bool pointer_arg_handler (const Expr *arg,
  48. struct PrintfArgChecker *ctx);
  49. static bool pid_arg_handler (const Expr *arg,
  50. struct PrintfArgChecker *ctx);
  51. static bool int64_arg_handler (const Expr *arg,
  52. struct PrintfArgChecker *ctx);
  53. static bool int32_arg_handler (const Expr *arg,
  54. struct PrintfArgChecker *ctx);
  55. static bool gboolean_arg_handler (const Expr *arg,
  56. struct PrintfArgChecker *ctx);
  57. static bool tok_arg_handler (const Expr *arg,
  58. struct PrintfArgChecker *ctx);
  59. static bool fstring_arg_handler (const Expr *arg,
  60. struct PrintfArgChecker *ctx);
  61. static bool gstring_arg_handler (const Expr *arg,
  62. struct PrintfArgChecker *ctx);
  63. static bool gerr_arg_handler (const Expr *arg,
  64. struct PrintfArgChecker *ctx);
  65. using arg_parser_t = bool (*) (const Expr *, struct PrintfArgChecker *);
  66. static void
  67. print_error (const std::string &err, const Expr *e, const ASTContext *ast,
  68. CompilerInstance *ci)
  69. {
  70. auto loc = e->getExprLoc ();
  71. auto &diag = ci->getDiagnostics ();
  72. auto id = diag.getCustomDiagID (DiagnosticsEngine::Error,
  73. "format query error: %0");
  74. diag.Report (loc, id) << err;
  75. }
  76. static void
  77. print_warning (const std::string &err, const Expr *e, const ASTContext *ast,
  78. CompilerInstance *ci)
  79. {
  80. auto loc = e->getExprLoc ();
  81. auto &diag = ci->getDiagnostics ();
  82. auto id = diag.getCustomDiagID (DiagnosticsEngine::Warning,
  83. "format query warning: %0");
  84. diag.Report (loc, id) << err;
  85. }
  86. struct PrintfArgChecker {
  87. private:
  88. arg_parser_t parser;
  89. public:
  90. int width;
  91. int precision;
  92. bool is_unsigned;
  93. ASTContext *past;
  94. CompilerInstance *pci;
  95. PrintfArgChecker (arg_parser_t _p, ASTContext *_ast, CompilerInstance *_ci) :
  96. parser (_p), past (_ast), pci(_ci)
  97. {
  98. width = 0;
  99. precision = 0;
  100. is_unsigned = false;
  101. }
  102. virtual ~PrintfArgChecker ()
  103. {
  104. }
  105. bool operator() (const Expr *e)
  106. {
  107. return parser (e, this);
  108. }
  109. };
  110. class PrintfCheckVisitor::impl {
  111. std::unordered_map<std::string, unsigned int> printf_functions;
  112. std::unordered_set<char> format_specs;
  113. ASTContext *pcontext;
  114. CompilerInstance *ci;
  115. std::unique_ptr <PrintfArgChecker> parseFlags (const std::string &flags,
  116. const Expr *e)
  117. {
  118. auto type = flags.back ();
  119. switch (type) {
  120. case 's':
  121. return llvm::make_unique<PrintfArgChecker> (cstring_arg_handler,
  122. this->pcontext, this->ci);
  123. case 'd':
  124. return llvm::make_unique<PrintfArgChecker> (int_arg_handler,
  125. this->pcontext, this->ci);
  126. case 'z':
  127. return llvm::make_unique<PrintfArgChecker> (size_arg_handler,
  128. this->pcontext, this->ci);
  129. case 'l':
  130. return llvm::make_unique<PrintfArgChecker> (long_arg_handler,
  131. this->pcontext, this->ci);
  132. case 'f':
  133. case 'g':
  134. return llvm::make_unique<PrintfArgChecker> (double_arg_handler,
  135. this->pcontext, this->ci);
  136. case 'F':
  137. case 'G':
  138. return llvm::make_unique<PrintfArgChecker> (
  139. long_double_arg_handler,
  140. this->pcontext, this->ci);
  141. case 'c':
  142. return llvm::make_unique<PrintfArgChecker> (char_arg_handler,
  143. this->pcontext, this->ci);
  144. case 'p':
  145. return llvm::make_unique<PrintfArgChecker> (pointer_arg_handler,
  146. this->pcontext, this->ci);
  147. case 'P':
  148. return llvm::make_unique<PrintfArgChecker> (pid_arg_handler,
  149. this->pcontext, this->ci);
  150. case 'L':
  151. return llvm::make_unique<PrintfArgChecker> (int64_arg_handler,
  152. this->pcontext, this->ci);
  153. case 'D':
  154. return llvm::make_unique<PrintfArgChecker> (int32_arg_handler,
  155. this->pcontext, this->ci);
  156. case 'B':
  157. return llvm::make_unique<PrintfArgChecker> (gboolean_arg_handler,
  158. this->pcontext, this->ci);
  159. case 'T':
  160. return llvm::make_unique<PrintfArgChecker> (tok_arg_handler,
  161. this->pcontext, this->ci);
  162. case 'V':
  163. return llvm::make_unique<PrintfArgChecker> (fstring_arg_handler,
  164. this->pcontext, this->ci);
  165. case 'v':
  166. return llvm::make_unique<PrintfArgChecker> (gstring_arg_handler,
  167. this->pcontext, this->ci);
  168. case 'e':
  169. return llvm::make_unique<PrintfArgChecker> (gerr_arg_handler,
  170. this->pcontext, this->ci);
  171. default:
  172. print_warning (std::string("unknown parser flag: ") + type,
  173. e, this->pcontext, this->ci);
  174. break;
  175. }
  176. return nullptr;
  177. }
  178. std::shared_ptr <std::vector<PrintfArgChecker>>
  179. genParsers (const StringRef query, const Expr *e)
  180. {
  181. enum {
  182. ignore_chars = 0,
  183. read_percent,
  184. read_width,
  185. read_precision,
  186. read_arg
  187. } state = ignore_chars;
  188. int width, precision;
  189. std::string flags;
  190. auto res = std::make_shared<std::vector<PrintfArgChecker> > ();
  191. for (auto citer = query.begin(); citer != query.end(); ++citer) {
  192. auto c = *citer;
  193. switch (state) {
  194. case ignore_chars:
  195. if (c == '%') {
  196. state = read_percent;
  197. flags.clear ();
  198. width = precision = 0;
  199. }
  200. break;
  201. case read_percent:
  202. if (isdigit (c)) {
  203. state = read_width;
  204. width = c - '0';
  205. }
  206. else if (c == '.') {
  207. state = read_precision;
  208. precision = c - '0';
  209. }
  210. else if (c == '*') {
  211. /* %*s - need integer argument */
  212. res->emplace_back (int_arg_handler, this->pcontext,
  213. this->ci);
  214. if (*std::next (citer) == '.') {
  215. ++citer;
  216. state = read_precision;
  217. }
  218. else {
  219. state = read_arg;
  220. }
  221. }
  222. else if (c == '%') {
  223. /* Percent character, ignore */
  224. state = ignore_chars;
  225. }
  226. else {
  227. // Rewind iter
  228. --citer;
  229. state = read_arg;
  230. }
  231. break;
  232. case read_width:
  233. if (isdigit (c)) {
  234. width *= 10;
  235. width += c - '0';
  236. }
  237. else if (c == '.') {
  238. state = read_precision;
  239. precision = c - '0';
  240. }
  241. else {
  242. // Rewind iter
  243. --citer;
  244. state = read_arg;
  245. }
  246. break;
  247. case read_precision:
  248. if (isdigit (c)) {
  249. precision *= 10;
  250. precision += c - '0';
  251. }
  252. else if (c == '*') {
  253. res->emplace_back (int_arg_handler, this->pcontext,
  254. this->ci);
  255. state = read_arg;
  256. }
  257. else {
  258. // Rewind iter
  259. --citer;
  260. state = read_arg;
  261. }
  262. break;
  263. case read_arg:
  264. auto found = format_specs.find (c);
  265. if (found != format_specs.end () || !isalpha (c)) {
  266. if (isalpha (c)) {
  267. flags.push_back (c);
  268. }
  269. auto handler = parseFlags (flags, e);
  270. if (handler) {
  271. auto handler_copy = *handler;
  272. handler_copy.precision = precision;
  273. handler_copy.width = width;
  274. res->emplace_back (std::move (handler_copy));
  275. }
  276. else {
  277. return nullptr;
  278. }
  279. if (c == '%') {
  280. state = read_percent;
  281. }
  282. else {
  283. state = ignore_chars;
  284. }
  285. flags.clear ();
  286. width = precision = 0;
  287. }
  288. else {
  289. flags.push_back (c);
  290. }
  291. break;
  292. }
  293. }
  294. if (state == read_arg) {
  295. auto handler = parseFlags (flags, e);
  296. if (handler) {
  297. auto handler_copy = *handler;
  298. handler_copy.precision = precision;
  299. handler_copy.width = width;
  300. res->emplace_back (std::move (handler_copy));
  301. }
  302. else {
  303. return nullptr;
  304. }
  305. }
  306. return res;
  307. }
  308. public:
  309. impl (ASTContext *_ctx, clang::CompilerInstance &_ci)
  310. : pcontext (_ctx), ci(&_ci)
  311. {
  312. /* name -> format string position */
  313. printf_functions = {
  314. {"rspamd_printf", 0},
  315. {"rspamd_default_log_function", 4},
  316. {"rspamd_snprintf", 2},
  317. {"rspamd_fprintf", 1},
  318. {"rspamd_printf_gstring", 1},
  319. {"rspamd_printf_fstring", 1}
  320. };
  321. format_specs = {
  322. 's', 'd', 'l', 'L', 'v', 'V', 'f', 'F', 'g', 'G',
  323. 'T', 'z', 'D', 'c', 'p', 'P', 'e', 'B'
  324. };
  325. };
  326. bool VisitCallExpr (CallExpr *E)
  327. {
  328. auto callee = dyn_cast<NamedDecl> (E->getCalleeDecl ());
  329. if (callee == NULL) {
  330. llvm::errs () << "Bad callee\n";
  331. return false;
  332. }
  333. auto fname = callee->getNameAsString ();
  334. auto pos_it = printf_functions.find (fname);
  335. if (pos_it != printf_functions.end ()) {
  336. const auto args = E->getArgs ();
  337. auto pos = pos_it->second;
  338. auto query = args[pos];
  339. if (!query->isEvaluatable (*pcontext)) {
  340. print_warning (std::string ("cannot evaluate query"),
  341. E, this->pcontext, this->ci);
  342. return false;
  343. }
  344. clang::Expr::EvalResult r;
  345. if (!query->EvaluateAsRValue (r, *pcontext)) {
  346. print_warning (std::string ("cannot evaluate rvalue of query"),
  347. E, this->pcontext, this->ci);
  348. return false;
  349. }
  350. auto qval = dyn_cast<StringLiteral> (
  351. r.Val.getLValueBase ().get<const Expr *> ());
  352. if (!qval) {
  353. print_warning (std::string ("bad or absent query string"),
  354. E, this->pcontext, this->ci);
  355. return false;
  356. }
  357. auto parsers = genParsers (qval->getString (), E);
  358. if (parsers) {
  359. if (parsers->size () != E->getNumArgs () - (pos + 1)) {
  360. std::ostringstream err_buf;
  361. err_buf << "number of arguments for " << fname
  362. << " missmatches query string '" <<
  363. qval->getString ().str ()
  364. << "', expected " << parsers->size () <<
  365. " args"
  366. << ", got " <<
  367. (E->getNumArgs () - (pos + 1))
  368. << " args";
  369. print_error (err_buf.str (), E, this->pcontext, this->ci);
  370. return false;
  371. }
  372. else {
  373. for (auto i = pos + 1; i < E->getNumArgs (); i++) {
  374. auto arg = args[i];
  375. if (arg) {
  376. if (!parsers->at (i - (pos + 1)) (arg)) {
  377. return false;
  378. }
  379. }
  380. }
  381. }
  382. }
  383. }
  384. return true;
  385. }
  386. };
  387. PrintfCheckVisitor::PrintfCheckVisitor (ASTContext *ctx,
  388. clang::CompilerInstance &ci) :
  389. pimpl{new impl (ctx, ci)}
  390. {
  391. }
  392. PrintfCheckVisitor::~PrintfCheckVisitor ()
  393. {
  394. }
  395. bool PrintfCheckVisitor::VisitCallExpr (clang::CallExpr *E)
  396. {
  397. return pimpl->VisitCallExpr (E);
  398. }
  399. /* Type handlers */
  400. static bool
  401. cstring_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
  402. {
  403. auto type = arg->getType ().split ().Ty;
  404. if (!type->isPointerType ()) {
  405. print_error (
  406. std::string ("bad string argument for %s: ") +
  407. arg->getType ().getAsString (),
  408. arg, ctx->past, ctx->pci);
  409. return false;
  410. }
  411. auto ptr_type = type->getPointeeType ().split ().Ty;
  412. if (!ptr_type->isCharType ()) {
  413. /* We might have gchar * here */
  414. auto desugared_type = ptr_type->getUnqualifiedDesugaredType ();
  415. auto desugared_ptr_type = type->getUnqualifiedDesugaredType ();
  416. if (!desugared_type || (!desugared_type->isCharType () &&
  417. !desugared_ptr_type->isVoidPointerType ())) {
  418. if (desugared_type) {
  419. desugared_type->dump ();
  420. }
  421. print_error (
  422. std::string ("bad string argument for %s: ") +
  423. arg->getType ().getAsString (),
  424. arg, ctx->past, ctx->pci);
  425. return false;
  426. }
  427. }
  428. return true;
  429. }
  430. static bool
  431. check_builtin_type (const Expr *arg, struct PrintfArgChecker *ctx,
  432. const std::vector <BuiltinType::Kind> &k, const std::string &fmt)
  433. {
  434. auto type = arg->getType ().split ().Ty;
  435. auto desugared_type = type->getUnqualifiedDesugaredType ();
  436. if (!desugared_type->isBuiltinType ()) {
  437. print_error (
  438. std::string ("not a builtin type for ") + fmt + " arg: " +
  439. arg->getType ().getAsString (),
  440. arg, ctx->past, ctx->pci);
  441. return false;
  442. }
  443. auto builtin_type = dyn_cast<BuiltinType> (desugared_type);
  444. auto kind = builtin_type->getKind ();
  445. auto found = false;
  446. for (auto kk : k) {
  447. if (kind == kk) {
  448. found = true;
  449. break;
  450. }
  451. }
  452. if (!found) {
  453. print_error (
  454. std::string ("bad argument for ") + fmt + " arg: " +
  455. arg->getType ().getAsString () + ", resolved as: " +
  456. builtin_type->getNameAsCString (ctx->past->getPrintingPolicy ()),
  457. arg, ctx->past, ctx->pci);
  458. return false;
  459. }
  460. return true;
  461. }
  462. static bool
  463. int_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
  464. {
  465. return check_builtin_type (arg,
  466. ctx,
  467. {BuiltinType::Kind::UInt,
  468. BuiltinType::Kind::Int},
  469. "%d or *");
  470. }
  471. static bool
  472. long_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
  473. {
  474. return check_builtin_type (arg,
  475. ctx,
  476. {BuiltinType::Kind::ULong,
  477. BuiltinType::Kind::Long},
  478. "%l");
  479. }
  480. static bool
  481. char_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
  482. {
  483. return check_builtin_type (arg,
  484. ctx,
  485. {BuiltinType::Kind::UChar,
  486. BuiltinType::Kind::SChar,
  487. BuiltinType::Kind::Int}, // Because of char -> int propagation
  488. "%c");
  489. }
  490. static bool
  491. size_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
  492. {
  493. if (sizeof (size_t) == sizeof (long)) {
  494. return check_builtin_type (arg,
  495. ctx,
  496. {BuiltinType::Kind::ULong,
  497. BuiltinType::Kind::Long},
  498. "%z");
  499. }
  500. else if (sizeof (size_t) == sizeof (int)) {
  501. return check_builtin_type (arg,
  502. ctx,
  503. {BuiltinType::Kind::UInt,
  504. BuiltinType::Kind::Int},
  505. "%z");
  506. }
  507. else {
  508. assert (0);
  509. }
  510. return true;
  511. }
  512. static bool
  513. double_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
  514. {
  515. return check_builtin_type (arg,
  516. ctx,
  517. {BuiltinType::Kind::Double},
  518. "%f or %g");
  519. }
  520. static bool
  521. long_double_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
  522. {
  523. return check_builtin_type (arg,
  524. ctx,
  525. {BuiltinType::Kind::LongDouble},
  526. "%F or %G");
  527. }
  528. static bool
  529. pid_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
  530. {
  531. if (sizeof (pid_t) == sizeof (long)) {
  532. return check_builtin_type (arg,
  533. ctx,
  534. {BuiltinType::Kind::ULong,
  535. BuiltinType::Kind::Long},
  536. "%P");
  537. }
  538. else if (sizeof (pid_t) == sizeof (int)) {
  539. return check_builtin_type (arg,
  540. ctx,
  541. {BuiltinType::Kind::UInt,
  542. BuiltinType::Kind::Int},
  543. "%P");
  544. }
  545. else {
  546. assert (0);
  547. }
  548. }
  549. static bool
  550. pointer_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
  551. {
  552. auto type = arg->getType ().split ().Ty;
  553. if (!type->isPointerType ()) {
  554. print_error (
  555. std::string ("bad pointer argument for %p: ") +
  556. arg->getType ().getAsString (),
  557. arg, ctx->past, ctx->pci);
  558. return false;
  559. }
  560. return true;
  561. }
  562. static bool
  563. int64_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
  564. {
  565. std::vector <BuiltinType::Kind> check;
  566. if (sizeof (int64_t) == sizeof (long long)) {
  567. check.push_back (BuiltinType::Kind::ULongLong);
  568. check.push_back (BuiltinType::Kind::LongLong);
  569. }
  570. if (sizeof (int64_t) == sizeof (long)) {
  571. check.push_back (BuiltinType::Kind::ULong);
  572. check.push_back (BuiltinType::Kind::Long);
  573. }
  574. return check_builtin_type (arg,
  575. ctx,
  576. check,
  577. "%L");
  578. return true;
  579. }
  580. static bool
  581. int32_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
  582. {
  583. std::vector < BuiltinType::Kind> check;
  584. if (sizeof (int32_t) == sizeof (long)) {
  585. check.push_back (BuiltinType::Kind::ULong);
  586. check.push_back (BuiltinType::Kind::Long);
  587. }
  588. if (sizeof (int32_t) == sizeof (int)) {
  589. check.push_back (BuiltinType::Kind::UInt);
  590. check.push_back (BuiltinType::Kind::Int);
  591. }
  592. return check_builtin_type (arg,
  593. ctx,
  594. check,
  595. "%D");
  596. return true;
  597. }
  598. static bool
  599. gboolean_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
  600. {
  601. return check_builtin_type (arg,
  602. ctx,
  603. {BuiltinType::Kind::Int}, // gboolean is int in fact
  604. "%b");
  605. }
  606. static bool
  607. check_struct_type (const Expr *arg, struct PrintfArgChecker *ctx,
  608. const std::string &sname, const std::string &fmt)
  609. {
  610. auto type = arg->getType ().split ().Ty;
  611. if (!type->isPointerType ()) {
  612. print_error (
  613. std::string ("bad string argument for %s: ") +
  614. arg->getType ().getAsString (),
  615. arg, ctx->past, ctx->pci);
  616. return false;
  617. }
  618. auto ptr_type = type->getPointeeType ().split ().Ty;
  619. auto desugared_type = ptr_type->getUnqualifiedDesugaredType ();
  620. if (!desugared_type->isRecordType ()) {
  621. print_error (
  622. std::string ("not a record type for ") + fmt + " arg: " +
  623. arg->getType ().getAsString (),
  624. arg, ctx->past, ctx->pci);
  625. return false;
  626. }
  627. auto struct_type = desugared_type->getAsStructureType ();
  628. auto struct_decl = struct_type->getDecl ();
  629. auto struct_def = struct_decl->getNameAsString ();
  630. if (struct_def != sname) {
  631. print_error (std::string ("bad argument '") + struct_def + "' for "
  632. + fmt + " arg: " +
  633. arg->getType ().getAsString (),
  634. arg, ctx->past, ctx->pci);
  635. return false;
  636. }
  637. return true;
  638. }
  639. static bool
  640. tok_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
  641. {
  642. return check_struct_type (arg,
  643. ctx,
  644. "f_str_tok",
  645. "%T");
  646. }
  647. static bool
  648. fstring_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
  649. {
  650. return check_struct_type (arg,
  651. ctx,
  652. "f_str_s",
  653. "%V");
  654. }
  655. static bool
  656. gstring_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
  657. {
  658. return check_struct_type (arg,
  659. ctx,
  660. "_GString",
  661. "%v");
  662. }
  663. static bool
  664. gerr_arg_handler (const Expr *arg, struct PrintfArgChecker *ctx)
  665. {
  666. return check_struct_type (arg,
  667. ctx,
  668. "_GError",
  669. "%e");
  670. }
  671. };