Skip to content

Copy constructor parameter instead of storing reference #3995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/util/allocate_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ class allocate_objectst
void mark_created_symbols_as_input(code_blockt &init_code);

private:
const irep_idt &symbol_mode;
const source_locationt &source_location;
const irep_idt &name_prefix;
const irep_idt symbol_mode;
const source_locationt source_location;
const irep_idt name_prefix;

symbol_table_baset &symbol_table;
const namespacet ns;
Expand Down
1 change: 1 addition & 0 deletions unit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ SRC += analyses/ai/ai.cpp \
solvers/strings/string_refinement/sparse_array.cpp \
solvers/strings/string_refinement/substitute_array_list.cpp \
solvers/strings/string_refinement/union_find_replace.cpp \
util/allocate_objects.cpp \
util/cmdline.cpp \
util/expr_cast/expr_cast.cpp \
util/expr.cpp \
Expand Down
30 changes: 30 additions & 0 deletions unit/util/allocate_objects.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************\

Module: Unit test for allocate_objectst

Author: Diffblue Ltd

\*******************************************************************/

#include <util/allocate_objects.h>
#include <util/c_types.h>
#include <util/irep_ids.h>
#include <util/source_location.h>
#include <util/symbol_table.h>

#include <testing-utils/use_catch.h>

TEST_CASE(
"Tests the absence of a bug that crashed allocate_objects",
"[core][util][allocate_objects]")
{
symbol_tablet symtab{};
// Because __a_temp will return a const reference to temporary
// irep_idt, and we stored the reference instead of copying the
// value ...
allocate_objectst allocate_object{
ID_C, source_locationt{}, "__a_temp", symtab};
// This crashed because it tried to access the invalid reference
// to the name_prefix irep_idt
allocate_object.allocate_automatic_local_object(size_type());
}