Skip to content

Commit 24295fa

Browse files
authored
Merge pull request #4051 from tautschnig/messaget-taint_analysis
taint_analysist isn't a messaget [blocks: #3800]
2 parents 9f30ce1 + f8b49a0 commit 24295fa

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

src/goto-analyzer/taint_analysis.cpp

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ Author: Daniel Kroening, [email protected]
2626

2727
#include "taint_parser.h"
2828

29-
class taint_analysist:public messaget
29+
class taint_analysist
3030
{
3131
public:
32-
taint_analysist()
32+
explicit taint_analysist(message_handlert &message_handler)
33+
: log(message_handler)
3334
{
3435
}
3536

@@ -41,6 +42,7 @@ class taint_analysist:public messaget
4142
const std::string &json_file_name);
4243

4344
protected:
45+
messaget log;
4446
taint_parse_treet taint;
4547
class_hierarchyt class_hierarchy;
4648

@@ -117,7 +119,8 @@ void taint_analysist::instrument(
117119

118120
if(match)
119121
{
120-
debug() << "MATCH " << rule.id << " on " << identifier << eom;
122+
log.debug() << "MATCH " << rule.id << " on " << identifier
123+
<< messaget::eom;
121124

122125
exprt where=nil_exprt();
123126

@@ -236,22 +239,24 @@ bool taint_analysist::operator()(
236239
json_arrayt json_result;
237240
bool use_json=!json_file_name.empty();
238241

239-
status() << "Reading taint file `" << taint_file_name
240-
<< "'" << eom;
242+
log.status() << "Reading taint file `" << taint_file_name << "'"
243+
<< messaget::eom;
241244

242-
if(taint_parser(taint_file_name, taint, get_message_handler()))
245+
if(taint_parser(taint_file_name, taint, log.get_message_handler()))
243246
{
244-
error() << "Failed to read taint definition file" << eom;
247+
log.error() << "Failed to read taint definition file" << messaget::eom;
245248
return true;
246249
}
247250

248-
status() << "Got " << taint.rules.size()
249-
<< " taint definitions" << eom;
251+
log.status() << "Got " << taint.rules.size() << " taint definitions"
252+
<< messaget::eom;
250253

251-
taint.output(debug());
252-
debug() << eom;
254+
log.conditional_output(log.debug(), [this](messaget::mstreamt &mstream) {
255+
taint.output(mstream);
256+
mstream << messaget::eom;
257+
});
253258

254-
status() << "Instrumenting taint" << eom;
259+
log.status() << "Instrumenting taint" << messaget::eom;
255260

256261
class_hierarchy(symbol_table);
257262

@@ -266,13 +271,13 @@ bool taint_analysist::operator()(
266271
// do we have an entry point?
267272
if(have_entry_point)
268273
{
269-
status() << "Working from entry point" << eom;
274+
log.status() << "Working from entry point" << messaget::eom;
270275
}
271276
else
272277
{
273-
status() << "No entry point found; "
274-
<< "we will consider the heads of all functions as reachable"
275-
<< eom;
278+
log.status() << "No entry point found; "
279+
<< "we will consider the heads of all functions as reachable"
280+
<< messaget::eom;
276281

277282
goto_programt end, gotos, calls;
278283

@@ -304,7 +309,7 @@ bool taint_analysist::operator()(
304309
goto_functions.update();
305310
}
306311

307-
status() << "Data-flow analysis" << eom;
312+
log.status() << "Data-flow analysis" << messaget::eom;
308313

309314
custom_bitvector_analysist custom_bitvector_analysis;
310315
custom_bitvector_analysis(goto_functions, ns);
@@ -385,13 +390,13 @@ bool taint_analysist::operator()(
385390

386391
if(!json_out)
387392
{
388-
error() << "Failed to open json output `"
389-
<< json_file_name << "'" << eom;
393+
log.error() << "Failed to open json output `" << json_file_name << "'"
394+
<< messaget::eom;
390395
return true;
391396
}
392397

393-
status() << "Analysis result is written to `"
394-
<< json_file_name << "'" << eom;
398+
log.status() << "Analysis result is written to `" << json_file_name << "'"
399+
<< messaget::eom;
395400

396401
json_out << json_result << '\n';
397402
}
@@ -400,17 +405,18 @@ bool taint_analysist::operator()(
400405
}
401406
catch(const char *error_msg)
402407
{
403-
error() << error_msg << eom;
408+
log.error() << error_msg << messaget::eom;
404409
return true;
405410
}
406411
catch(const std::string &error_msg)
407412
{
408-
error() << error_msg << eom;
413+
log.error() << error_msg << messaget::eom;
409414
return true;
410415
}
411416
catch(...)
412417
{
413-
error() << "Caught unexpected error in taint_analysist::operator()" << eom;
418+
log.error() << "Caught unexpected error in taint_analysist::operator()"
419+
<< messaget::eom;
414420
return true;
415421
}
416422
}
@@ -422,8 +428,7 @@ bool taint_analysis(
422428
bool show_full,
423429
const std::string &json_file_name)
424430
{
425-
taint_analysist taint_analysis;
426-
taint_analysis.set_message_handler(message_handler);
431+
taint_analysist taint_analysis(message_handler);
427432
return taint_analysis(
428433
taint_file_name,
429434
goto_model.symbol_table,

0 commit comments

Comments
 (0)