Skip to content

Commit 80e4214

Browse files
author
Daniel Kroening
authored
Merge pull request #1159 from reuk/use-nullptr-master
[depends: #1063] Use nullptr to represent null pointers (targets master)
2 parents e18cb15 + 52e5765 commit 80e4214

File tree

83 files changed

+324
-296
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+324
-296
lines changed

src/analyses/goto_check.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class goto_checkt
3737
const namespacet &_ns,
3838
const optionst &_options):
3939
ns(_ns),
40-
local_bitvector_analysis(0)
40+
local_bitvector_analysis(nullptr)
4141
{
4242
enable_bounds_check=_options.get_bool_option("bounds-check");
4343
enable_pointer_check=_options.get_bool_option("pointer-check");

src/analyses/goto_rw.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,10 @@ void rw_range_sett::add(
463463
{
464464
objectst::iterator entry=(mode==get_modet::LHS_W ? w_range_set : r_range_set).
465465
insert(
466-
std::pair<const irep_idt&, range_domain_baset*>(identifier, 0)).first;
466+
std::pair<const irep_idt&, range_domain_baset*>(
467+
identifier, nullptr)).first;
467468

468-
if(entry->second==0)
469+
if(entry->second==nullptr)
469470
entry->second=new range_domaint();
470471

471472
static_cast<range_domaint*>(entry->second)->push_back(
@@ -663,9 +664,10 @@ void rw_guarded_range_set_value_sett::add(
663664
{
664665
objectst::iterator entry=(mode==get_modet::LHS_W ? w_range_set : r_range_set).
665666
insert(
666-
std::pair<const irep_idt&, range_domain_baset*>(identifier, 0)).first;
667+
std::pair<const irep_idt&, range_domain_baset*>(
668+
identifier, nullptr)).first;
667669

668-
if(entry->second==0)
670+
if(entry->second==nullptr)
669671
entry->second=new guarded_range_domaint();
670672

671673
static_cast<guarded_range_domaint*>(entry->second)->insert(

src/analyses/goto_rw.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class rw_range_sett
108108

109109
const range_domaint &get_ranges(objectst::const_iterator it) const
110110
{
111-
assert(dynamic_cast<range_domaint*>(it->second)!=0);
111+
PRECONDITION(dynamic_cast<range_domaint*>(it->second)!=nullptr);
112112
return *static_cast<range_domaint*>(it->second);
113113
}
114114

@@ -277,7 +277,7 @@ class rw_guarded_range_set_value_sett:public rw_range_set_value_sett
277277

278278
const guarded_range_domaint &get_ranges(objectst::const_iterator it) const
279279
{
280-
assert(dynamic_cast<guarded_range_domaint*>(it->second)!=0);
280+
PRECONDITION(dynamic_cast<guarded_range_domaint*>(it->second)!=nullptr);
281281
return *static_cast<guarded_range_domaint*>(it->second);
282282
}
283283

src/analyses/invariant_set.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ bool invariant_sett::get_object(
144144
const exprt &expr,
145145
unsigned &n) const
146146
{
147-
assert(object_store!=NULL);
147+
PRECONDITION(object_store!=nullptr);
148148
return object_store->get(expr, n);
149149
}
150150

@@ -315,7 +315,8 @@ void invariant_sett::output(
315315
return;
316316
}
317317

318-
assert(object_store!=NULL);
318+
INVARIANT(
319+
object_store!=nullptr, nullptr_exceptiont("Object store is null"));
319320

320321
for(unsigned i=0; i<eq_set.size(); i++)
321322
if(eq_set.is_root(i) &&
@@ -899,7 +900,7 @@ std::string invariant_sett::to_string(
899900
unsigned a,
900901
const irep_idt &identifier) const
901902
{
902-
assert(object_store!=NULL);
903+
PRECONDITION(object_store!=nullptr);
903904
return object_store->to_string(a, identifier);
904905
}
905906

src/analyses/invariant_set.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Author: Daniel Kroening, [email protected]
2222

2323
#include "interval_template.h"
2424

25+
#define nullptr_exceptiont(str) str
26+
2527
class inv_object_storet
2628
{
2729
public:
@@ -98,9 +100,9 @@ class invariant_sett
98100
invariant_sett():
99101
threaded(false),
100102
is_false(false),
101-
value_sets(NULL),
102-
object_store(NULL),
103-
ns(NULL)
103+
value_sets(nullptr),
104+
object_store(nullptr),
105+
ns(nullptr)
104106
{
105107
}
106108

src/analyses/local_may_alias.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class local_may_aliast
9494
class local_may_alias_factoryt
9595
{
9696
public:
97-
local_may_alias_factoryt():goto_functions(NULL)
97+
local_may_alias_factoryt():goto_functions(nullptr)
9898
{
9999
}
100100

@@ -109,7 +109,7 @@ class local_may_alias_factoryt
109109

110110
local_may_aliast &operator()(const irep_idt &fkt)
111111
{
112-
assert(goto_functions!=NULL);
112+
PRECONDITION(goto_functions!=nullptr);
113113
fkt_mapt::iterator f_it=fkt_map.find(fkt);
114114
if(f_it!=fkt_map.end())
115115
return *f_it->second;

src/analyses/reaching_definitions.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ void rd_range_domaint::transform(
5151
{
5252
reaching_definitions_analysist *rd=
5353
dynamic_cast<reaching_definitions_analysist*>(&ai);
54-
assert(rd!=0);
54+
INVARIANT(
55+
rd!=nullptr,
56+
bad_cast_exceptiont("ai has type reaching_definitions_analysist"));
5557

5658
assert(bv_container);
5759

@@ -298,7 +300,9 @@ void rd_range_domaint::transform_assign(
298300
const symbolt *symbol_ptr;
299301
if(ns.lookup(identifier, symbol_ptr))
300302
continue;
301-
assert(symbol_ptr!=0);
303+
INVARIANT(
304+
symbol_ptr!=nullptr,
305+
nullptr_exceptiont("Symbol is in symbol table"));
302306

303307
const range_domaint &ranges=rw_set.get_ranges(it);
304308

src/analyses/reaching_definitions.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class is_threadedt;
2626
class dirtyt;
2727
class reaching_definitions_analysist;
2828

29+
#define bad_cast_exceptiont(str) str
30+
#define nullptr_exceptiont(str) str
31+
2932
// requirement: V has a member "identifier" of type irep_idt
3033
template<typename V>
3134
class sparse_bitvector_analysist
@@ -102,7 +105,7 @@ class rd_range_domaint:public ai_domain_baset
102105
rd_range_domaint():
103106
ai_domain_baset(),
104107
has_values(false),
105-
bv_container(0)
108+
bv_container(nullptr)
106109
{
107110
}
108111

@@ -243,9 +246,9 @@ class reaching_definitions_analysist:
243246
explicit reaching_definitions_analysist(const namespacet &_ns):
244247
concurrency_aware_ait<rd_range_domaint>(),
245248
ns(_ns),
246-
value_sets(0),
247-
is_threaded(0),
248-
is_dirty(0)
249+
value_sets(nullptr),
250+
is_threaded(nullptr),
251+
is_dirty(nullptr)
249252
{
250253
}
251254

@@ -259,7 +262,9 @@ class reaching_definitions_analysist:
259262
statet &s=concurrency_aware_ait<rd_range_domaint>::get_state(l);
260263

261264
rd_range_domaint *rd_state=dynamic_cast<rd_range_domaint*>(&s);
262-
assert(rd_state!=0);
265+
INVARIANT(
266+
rd_state!=nullptr,
267+
bad_cast_exceptiont("rd_state has type rd_range_domaint"));
263268

264269
rd_state->set_bitvector_container(*this);
265270

src/ansi-c/c_preprocess.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ bool c_preprocess(
344344
static bool is_dot_i_file(const std::string &path)
345345
{
346346
const char *ext=strrchr(path.c_str(), '.');
347-
if(ext==NULL)
347+
if(ext==nullptr)
348348
return false;
349349
if(std::string(ext)==".i" ||
350350
std::string(ext)==".ii")
@@ -889,7 +889,7 @@ bool c_preprocess_gcc_clang(
889889

890890
FILE *stream=popen(command.c_str(), "r");
891891

892-
if(stream!=NULL)
892+
if(stream!=nullptr)
893893
{
894894
int ch;
895895
while((ch=fgetc(stream))!=EOF)
@@ -1011,7 +1011,7 @@ bool c_preprocess_arm(
10111011

10121012
FILE *stream=popen(command.c_str(), "r");
10131013

1014-
if(stream!=NULL)
1014+
if(stream!=nullptr)
10151015
{
10161016
int ch;
10171017
while((ch=fgetc(stream))!=EOF)

src/ansi-c/cprover_library.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ std::string get_cprover_library_text(
3838
std::size_t count=0;
3939

4040
for(cprover_library_entryt *e=cprover_library;
41-
e->function!=NULL;
41+
e->function!=nullptr;
4242
e++)
4343
{
4444
irep_idt id=e->function;

src/ansi-c/expr2c.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2664,7 +2664,7 @@ std::string expr2ct::convert_code_decl(
26642664

26652665
std::string dest=indent_str(indent);
26662666

2667-
const symbolt *symbol=0;
2667+
const symbolt *symbol=nullptr;
26682668
if(!ns.lookup(to_symbol_expr(src.op0()).get_identifier(), symbol))
26692669
{
26702670
if(symbol->is_file_local &&

src/big-int/bigint-test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static void
161161
run_clisp_tests (char const *fn)
162162
{
163163
FILE *f = fopen (fn, "rt");
164-
if (f == 0)
164+
if (f == nullptr)
165165
{
166166
fprintf (stderr, "Error opening %s: %s.\n", fn, strerror (errno));
167167
return;

src/big-int/bigint.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ digit_div (onedig_t *r, const onedig_t *y, unsigned yl, onedig_t *q, unsigned ql
266266
--qh;
267267
add_back (r, y, yl);
268268
}
269-
if (q != 0)
269+
if (q != nullptr)
270270
q[i] = qh;
271271
}
272272
}
@@ -580,7 +580,7 @@ char *
580580
BigInt::as_string (char *p, unsigned l, onedig_t b) const
581581
{
582582
if (l < 2)
583-
return 0; // Not enough room for number.
583+
return nullptr; // Not enough room for number.
584584
p[--l] = '\0';
585585
// Check for zero. Would otherwise print as empty string.
586586
unsigned len = length;
@@ -598,7 +598,7 @@ BigInt::as_string (char *p, unsigned l, onedig_t b) const
598598
do
599599
{
600600
if (l == 0)
601-
return 0;
601+
return nullptr;
602602
onedig_t r = digit_div (dig, len, b);
603603
p[--l] = r < 10 ? r + '0' : 'A' + r - 10;
604604
if (dig[len-1] == 0)
@@ -608,7 +608,7 @@ BigInt::as_string (char *p, unsigned l, onedig_t b) const
608608
// Maybe attach sign.
609609
if (!positive){
610610
if (l == 0)
611-
return 0;
611+
return nullptr;
612612
else
613613
p[--l] = '-';
614614
}
@@ -1268,7 +1268,7 @@ BigInt::operator%= (BigInt const &y)
12681268
}
12691269
if (a[al-1] >= b[bl-1])
12701270
a[al++] = 0;
1271-
digit_div (a, b, bl, 0, al - bl);
1271+
digit_div (a, b, bl, nullptr, al - bl);
12721272
length = bl;
12731273
adjust();
12741274
if (scale != 1)

src/cbmc/cbmc_parse_options.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ int cbmc_parse_optionst::get_goto_program(
590590

591591
languaget *language=get_language_from_filename(filename);
592592

593-
if(language==NULL)
593+
if(language==nullptr)
594594
{
595595
error() << "failed to figure out type of file `"
596596
<< filename << "'" << eom;
@@ -739,7 +739,7 @@ void cbmc_parse_optionst::preprocessing()
739739

740740
languaget *ptr=get_language_from_filename(filename);
741741

742-
if(ptr==NULL)
742+
if(ptr==nullptr)
743743
{
744744
error() << "failed to figure out type of file" << eom;
745745
return;

src/clobber/clobber_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ bool clobber_parse_optionst::get_goto_program(
250250

251251
languaget *language=get_language_from_filename(filename);
252252

253-
if(language==NULL)
253+
if(language==nullptr)
254254
{
255255
error() << "failed to figure out type of file `" << filename << "'"
256256
<< eom;

src/cpp/cpp_id.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ cpp_idt::cpp_idt():
2424
id_class(id_classt::UNKNOWN),
2525
this_expr(static_cast<const exprt &>(get_nil_irep())),
2626
compound_counter(0),
27-
parent(NULL)
27+
parent(nullptr)
2828
{
2929
}
3030

src/cpp/cpp_id.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Author: Daniel Kroening, [email protected]
2020
#include <iosfwd>
2121

2222
#include <util/expr.h>
23+
#include <util/invariant.h>
2324
#include <util/std_types.h>
2425

2526
class cpp_scopet;
@@ -81,7 +82,7 @@ class cpp_idt
8182

8283
cpp_idt &get_parent() const
8384
{
84-
assert(parent!=NULL);
85+
PRECONDITION(parent!=nullptr);
8586
return *parent;
8687
}
8788

src/cpp/cpp_instantiate_template.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ const symbolt &cpp_typecheckt::class_template_symbol(
130130
cpp_scopet *template_scope=
131131
static_cast<cpp_scopet *>(cpp_scopes.id_map[template_symbol.name]);
132132

133-
assert(template_scope!=NULL);
133+
INVARIANT(
134+
template_scope!=nullptr, nullptr_exceptiont("template_scope is null"));
134135

135136
irep_idt identifier=
136137
id2string(template_scope->prefix)+
@@ -276,15 +277,16 @@ const symbolt &cpp_typecheckt::instantiate_template(
276277
cpp_scopet *template_scope=
277278
static_cast<cpp_scopet *>(cpp_scopes.id_map[template_symbol.name]);
278279

279-
if(template_scope==NULL)
280+
if(template_scope==nullptr)
280281
{
281282
error().source_location=source_location;
282283
error() << "identifier: " << template_symbol.name << '\n'
283284
<< "template instantiation error: scope not found" << eom;
284285
throw 0;
285286
}
286287

287-
assert(template_scope!=NULL);
288+
INVARIANT(
289+
template_scope!=nullptr, nullptr_exceptiont("template_scope is null"));
288290

289291
// produce new declaration
290292
cpp_declarationt new_decl=to_cpp_declaration(template_symbol.type);

src/cpp/cpp_language.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ bool cpp_languaget::preprocess(
6565
// check extension
6666

6767
const char *ext=strrchr(path.c_str(), '.');
68-
if(ext!=NULL && std::string(ext)==".ipp")
68+
if(ext!=nullptr && std::string(ext)==".ipp")
6969
{
7070
std::ifstream infile(path);
7171

src/cpp/cpp_typecheck.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Author: Daniel Kroening, [email protected]
3030
#include "cpp_template_type.h"
3131
#include "cpp_util.h"
3232

33+
#define nullptr_exceptiont(str) str
34+
3335
bool cpp_typecheck(
3436
cpp_parse_treet &cpp_parse_tree,
3537
symbol_tablet &symbol_table,

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void cpp_typecheckt::typecheck_compound_type(
110110
// get the tag name
111111
bool has_tag=type.find(ID_tag).is_not_nil();
112112
irep_idt base_name;
113-
cpp_scopet *dest_scope=NULL;
113+
cpp_scopet *dest_scope=nullptr;
114114
bool has_body=type.find(ID_body).is_not_nil();
115115
bool tag_only_declaration=type.get_bool(ID_C_tag_only_declaration);
116116

0 commit comments

Comments
 (0)