Skip to content

Commit d115b4e

Browse files
catch by const ref instead of by value or non-const ref
This PR makes the update universally for std::string (where the contents of the whole string will be copied) and bad_alloc (where memory is already short). These two are particularly prevalent.
1 parent 912ee38 commit d115b4e

18 files changed

+31
-31
lines changed

src/cbmc/bmc.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ safety_checkert::resultt bmct::run(
371371
return safety_checkert::resultt::ERROR;
372372
}
373373

374-
catch(std::bad_alloc)
374+
catch(const std::bad_alloc &)
375375
{
376376
error() << "Out of memory" << eom;
377377
return safety_checkert::resultt::ERROR;
@@ -471,7 +471,7 @@ safety_checkert::resultt bmct::run(
471471
return decide(goto_functions, prop_conv);
472472
}
473473

474-
catch(std::string &error_str)
474+
catch(const std::string &error_str)
475475
{
476476
error() << error_str << eom;
477477
return safety_checkert::resultt::ERROR;
@@ -483,7 +483,7 @@ safety_checkert::resultt bmct::run(
483483
return safety_checkert::resultt::ERROR;
484484
}
485485

486-
catch(std::bad_alloc)
486+
catch(const std::bad_alloc &)
487487
{
488488
error() << "Out of memory" << eom;
489489
return safety_checkert::resultt::ERROR;

src/cbmc/cbmc_parse_options.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ int cbmc_parse_optionst::get_goto_program(
659659
return 6;
660660
}
661661

662-
catch(std::bad_alloc)
662+
catch(const std::bad_alloc &)
663663
{
664664
error() << "Out of memory" << eom;
665665
return 6;
@@ -717,7 +717,7 @@ void cbmc_parse_optionst::preprocessing()
717717
{
718718
}
719719

720-
catch(std::bad_alloc)
720+
catch(const std::bad_alloc &)
721721
{
722722
error() << "Out of memory" << eom;
723723
}
@@ -851,7 +851,7 @@ bool cbmc_parse_optionst::process_goto_program(
851851
return true;
852852
}
853853

854-
catch(std::bad_alloc)
854+
catch(const std::bad_alloc &)
855855
{
856856
error() << "Out of memory" << eom;
857857
return true;

src/clobber/clobber_parse_options.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ int clobber_parse_optionst::doit()
166166
return 8;
167167
}
168168

169-
catch(std::bad_alloc)
169+
catch(const std::bad_alloc &)
170170
{
171171
error() << "Out of memory" << messaget::eom;
172172
return 8;

src/goto-analyzer/goto_analyzer_parse_options.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ bool goto_analyzer_parse_optionst::process_goto_program(
414414
return true;
415415
}
416416

417-
catch(std::bad_alloc)
417+
catch(const std::bad_alloc &)
418418
{
419419
error() << "Out of memory" << eom;
420420
return true;

src/goto-cc/goto_cc_mode.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int goto_cc_modet::main(int argc, const char **argv)
9999
return EX_SOFTWARE;
100100
}
101101

102-
catch(std::bad_alloc)
102+
catch(const std::bad_alloc &)
103103
{
104104
error() << "Out of memory" << eom;
105105
return EX_SOFTWARE;

src/goto-diff/goto_diff_parse_options.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ bool goto_diff_parse_optionst::process_goto_program(
460460
return true;
461461
}
462462

463-
catch(std::bad_alloc)
463+
catch(const std::bad_alloc &)
464464
{
465465
error() << "Out of memory" << eom;
466466
return true;

src/goto-instrument/accelerate/acceleration_utils.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ bool acceleration_utilst::check_inductive(
181181
return true;
182182
}
183183
}
184-
catch(std::string s)
184+
catch(const std::string &s)
185185
{
186186
std::cout << "Error in inductiveness SAT check: " << s << '\n';
187187
return false;
@@ -458,7 +458,7 @@ bool acceleration_utilst::do_assumptions(
458458
return false;
459459
}
460460
}
461-
catch(std::string s)
461+
catch(const std::string &s)
462462
{
463463
std::cout << "Error in monotonicity SAT check: " << s << '\n';
464464
return false;

src/goto-instrument/accelerate/disjunctive_polynomial_acceleration.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ bool disjunctive_polynomial_accelerationt::accelerate(
248248
{
249249
path_is_monotone=utils.do_assumptions(polynomials, path, guard);
250250
}
251-
catch(std::string s)
251+
catch(const std::string &s)
252252
{
253253
// Couldn't do WP.
254254
std::cout << "Assumptions error: " << s << '\n';
@@ -389,7 +389,7 @@ bool disjunctive_polynomial_accelerationt::find_path(patht &path)
389389
return true;
390390
}
391391
}
392-
catch(std::string s)
392+
catch(const std::string &s)
393393
{
394394
std::cout << "Error in fitting polynomial SAT check: " << s << '\n';
395395
}
@@ -637,7 +637,7 @@ bool disjunctive_polynomial_accelerationt::fit_polynomial(
637637
return true;
638638
}
639639
}
640-
catch(std::string s)
640+
catch(const std::string &s)
641641
{
642642
std::cout << "Error in fitting polynomial SAT check: " << s << '\n';
643643
}

src/goto-instrument/accelerate/polynomial_accelerator.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ bool polynomial_acceleratort::accelerate(
181181
{
182182
path_is_monotone=utils.do_assumptions(polynomials, loop, guard);
183183
}
184-
catch (std::string s)
184+
catch(const std::string &s)
185185
{
186186
// Couldn't do WP.
187187
std::cout << "Assumptions error: " << s << '\n';
@@ -424,7 +424,7 @@ bool polynomial_acceleratort::fit_polynomial_sliced(
424424
return true;
425425
}
426426
}
427-
catch(std::string s)
427+
catch(const std::string &s)
428428
{
429429
std::cout << "Error in fitting polynomial SAT check: " << s << '\n';
430430
}
@@ -485,7 +485,7 @@ bool polynomial_acceleratort::fit_const(
485485
return true;
486486
}
487487
}
488-
catch(std::string s)
488+
catch(const std::string &s)
489489
{
490490
std::cout << "Error in fitting polynomial SAT check: " << s << '\n';
491491
}
@@ -719,7 +719,7 @@ bool polynomial_acceleratort::check_inductive(
719719
return true;
720720
}
721721
}
722-
catch(std::string s)
722+
catch(const std::string &s)
723723
{
724724
std::cout << "Error in inductiveness SAT check: " << s << '\n';
725725
return false;

src/goto-instrument/accelerate/sat_path_enumerator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ bool sat_path_enumeratort::next(patht &path)
9595
return true;
9696
}
9797
}
98-
catch(std::string s)
98+
catch(const std::string &s)
9999
{
100100
std::cout << "Error in fitting polynomial SAT check: " << s << '\n';
101101
}

src/goto-instrument/goto_instrument_parse_options.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ int goto_instrument_parse_optionst::doit()
824824
return 11;
825825
}
826826

827-
catch(std::bad_alloc)
827+
catch(const std::bad_alloc &)
828828
{
829829
error() << "Out of memory" << eom;
830830
return 11;

src/goto-instrument/wmm/goto2graph.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ bool inline instrumentert::local(const irep_idt &id)
7676

7777
return false;
7878
}
79-
catch(std::string exception)
79+
catch(const std::string &exception)
8080
{
8181
message.debug()<<"Exception: "<<exception << messaget::eom;
8282
return false;
@@ -714,7 +714,7 @@ void instrumentert::cfg_visitort::visit_cfg_function_call(
714714
cur_fun=stack_fun.pop();
715715
#endif
716716
}
717-
catch(std::string s)
717+
catch(const std::string &s)
718718
{
719719
instrumenter.message.warning() << "sorry, doesn't handle recursion "
720720
<< "(function " << fun_id << "; .cpp) "

src/goto-instrument/wmm/goto2graph.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class instrumentert
251251
function, empty_in, end_out);
252252
leave_function(function);
253253
}
254-
catch(std::string s)
254+
catch(const std::string &s)
255255
{
256256
instrumenter.message.warning() << s << messaget::eom;
257257
}

src/goto-instrument/wmm/pair_collection.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void event_grapht::graph_pensieve_explorert::collect_pairs(namespacet &ns)
5353
first_event.source_location.get_line(), first_event.variable,
5454
static_cast<int>(first_event.operation));
5555
}
56-
catch(std::string s)
56+
catch(const std::string &s)
5757
{
5858
egraph.message.warning() << "failed to find" << s << messaget::eom;
5959
continue;

src/goto-instrument/wmm/shared_buffers.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void shared_bufferst::assignment(
177177

178178
t++;
179179
}
180-
catch(std::string s)
180+
catch(const std::string &s)
181181
{
182182
message.warning() << s << messaget::eom;
183183
}
@@ -929,7 +929,7 @@ void shared_bufferst::nondet_flush(
929929
buff1_thd_3_expr))))));
930930
}
931931
}
932-
catch (std::string s)
932+
catch(const std::string &s)
933933
{
934934
message.warning() << s << messaget::eom;
935935
}

src/goto-programs/initialize_goto_model.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ bool initialize_goto_model(
193193
{
194194
return true;
195195
}
196-
catch(std::bad_alloc)
196+
catch(const std::bad_alloc &)
197197
{
198198
msg.error() << "Out of memory" << messaget::eom;
199199
return true;

src/jbmc/jbmc_parse_options.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ int jbmc_parse_optionst::get_goto_program(
619619
return 6;
620620
}
621621

622-
catch(std::bad_alloc)
622+
catch(const std::bad_alloc &)
623623
{
624624
error() << "Out of memory" << eom;
625625
return 6;
@@ -783,7 +783,7 @@ bool jbmc_parse_optionst::process_goto_program(
783783
return true;
784784
}
785785

786-
catch(std::bad_alloc)
786+
catch(const std::bad_alloc &)
787787
{
788788
error() << "Out of memory" << eom;
789789
return true;

unit/wp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int main(int argc, const char **argv)
7575
}
7676
}
7777

78-
catch(std::string s)
78+
catch(const std::string &s)
7979
{
8080
std::cerr << s << std::endl;
8181
}

0 commit comments

Comments
 (0)