-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path3271-Remove-unnecessary-nullptr-checks.patch
1815 lines (1627 loc) · 61 KB
/
3271-Remove-unnecessary-nullptr-checks.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Andrew Strelsky <[email protected]>
Date: Tue, 27 Jul 2021 20:43:36 -0400
Subject: [PATCH] 3271: Remove unnecessary nullptr checks
The C++ language GUARANTEES that delete will do nothing if given null
---
.../Decompiler/src/decompile/cpp/action.cc | 17 ++---
.../src/decompile/cpp/architecture.cc | 54 ++++++----------
.../Decompiler/src/decompile/cpp/block.cc | 6 +-
.../src/decompile/cpp/blockaction.cc | 8 +--
.../Decompiler/src/decompile/cpp/comment.cc | 12 ++--
.../Decompiler/src/decompile/cpp/context.hh | 2 +-
.../Decompiler/src/decompile/cpp/cpool.hh | 2 +-
.../Decompiler/src/decompile/cpp/database.cc | 28 +++------
.../Decompiler/src/decompile/cpp/emulate.cc | 8 +--
.../src/decompile/cpp/emulateutil.cc | 8 +--
.../Decompiler/src/decompile/cpp/fspec.cc | 63 ++++++-------------
.../Decompiler/src/decompile/cpp/funcdata.hh | 2 +-
.../src/decompile/cpp/ghidra_process.cc | 14 ++---
.../Decompiler/src/decompile/cpp/grammar.cc | 41 +++++-------
.../Decompiler/src/decompile/cpp/grammar.y | 41 +++++-------
.../src/decompile/cpp/ifacedecomp.cc | 15 ++---
.../src/decompile/cpp/inject_sleigh.cc | 14 ++---
.../Decompiler/src/decompile/cpp/interface.cc | 36 ++++-------
.../Decompiler/src/decompile/cpp/jumptable.cc | 47 +++++---------
.../Decompiler/src/decompile/cpp/loadimage.cc | 5 +-
.../src/decompile/cpp/loadimage_bfd.cc | 6 +-
.../Decompiler/src/decompile/cpp/memstate.cc | 6 +-
.../Decompiler/src/decompile/cpp/op.cc | 14 ++---
.../Decompiler/src/decompile/cpp/options.cc | 5 +-
.../Decompiler/src/decompile/cpp/override.cc | 6 +-
.../src/decompile/cpp/pcodecompile.cc | 3 +-
.../src/decompile/cpp/pcodeinject.cc | 5 +-
.../src/decompile/cpp/pcodeinject.hh | 2 +-
.../src/decompile/cpp/pcodeparse.cc | 24 +++----
.../Decompiler/src/decompile/cpp/pcodeparse.y | 18 ++----
.../Decompiler/src/decompile/cpp/printjava.cc | 3 +-
.../src/decompile/cpp/printlanguage.cc | 3 +-
.../src/decompile/cpp/rulecompile.cc | 16 ++---
.../Decompiler/src/decompile/cpp/semantics.cc | 22 +++----
.../Decompiler/src/decompile/cpp/sleigh.cc | 3 +-
.../src/decompile/cpp/slghpattern.cc | 12 ++--
.../src/decompile/cpp/slghpattern.hh | 4 +-
.../src/decompile/cpp/slghsymbol.cc | 49 ++++++---------
.../src/decompile/cpp/slghsymbol.hh | 2 +-
.../Decompiler/src/decompile/cpp/transform.cc | 5 +-
.../Decompiler/src/decompile/cpp/translate.cc | 9 +--
.../Decompiler/src/decompile/cpp/type.cc | 12 ++--
.../Decompiler/src/decompile/cpp/typeop.cc | 3 +-
.../Decompiler/src/decompile/cpp/unify.cc | 9 +--
.../Decompiler/src/decompile/cpp/userop.cc | 14 ++---
.../Decompiler/src/decompile/cpp/varmap.cc | 5 +-
.../Decompiler/src/decompile/cpp/varnode.cc | 18 ++----
.../Decompiler/src/decompile/cpp/xml.cc | 15 ++---
.../Decompiler/src/decompile/cpp/xml.y | 15 ++---
49 files changed, 259 insertions(+), 472 deletions(-)
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/action.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/action.cc
index 9a4e2e26d0..4031b6c878 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/action.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/action.cc
@@ -364,10 +364,8 @@ int4 Action::perform(Funcdata &data)
ActionGroup::~ActionGroup(void)
{
- vector<Action *>::iterator iter;
-
- for(iter=list.begin();iter!=list.end();++iter)
- delete *iter;
+ for(auto *it : list)
+ delete it;
}
/// To be used only during the construction of \b this ActionGroup. This routine
@@ -728,10 +726,8 @@ bool Rule::checkActionBreak(void)
ActionPool::~ActionPool(void)
{
- vector<Rule *>::iterator iter;
-
- for(iter=allrules.begin();iter!=allrules.end();++iter)
- delete *iter;
+ for(auto *it : allrules)
+ delete it;
}
/// This method should only be invoked during construction of this ActionPool
@@ -976,9 +972,8 @@ const char ActionDatabase::universalname[] = "universal";
ActionDatabase::~ActionDatabase(void)
{
- map<string,Action *>::iterator iter;
- for(iter = actionmap.begin();iter!=actionmap.end();++iter)
- delete (*iter).second;
+ for(auto &it : actionmap)
+ delete it.second;
}
/// Clear out (possibly altered) root Actions. Reset the default groups.
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc
index 4cccca2ca5..4072e27dcf 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc
@@ -184,46 +184,30 @@ Architecture::Architecture(void)
Architecture::~Architecture(void)
{ // Delete anything that was allocated
- vector<TypeOp *>::iterator iter;
- TypeOp *t_op;
-
- for(iter=inst.begin();iter!=inst.end();++iter) {
- t_op = *iter;
- if (t_op != (TypeOp *)0)
- delete t_op;
- }
- for(int4 i=0;i<extra_pool_rules.size();++i)
- delete extra_pool_rules[i];
-
- if (symboltab != (Database *)0)
- delete symboltab;
- for(int4 i=0;i<(int4)printlist.size();++i)
- delete printlist[i];
+ for(TypeOp *op : inst)
+ delete op;
+ for(Rule *rule : extra_pool_rules)
+ delete rule;
+
+ delete symboltab;
+ for(PrintLanguage *lang : printlist)
+ delete lang;
delete options;
#ifdef CPUI_STATISTICS
delete stats;
#endif
- map<string,ProtoModel *>::const_iterator piter;
- for(piter=protoModels.begin();piter!=protoModels.end();++piter)
- delete (*piter).second;
-
- if (types != (TypeFactory *)0)
- delete types;
- if (translate != (Translate *)0)
- delete translate;
- if (loader != (LoadImage *)0)
- delete loader;
- if (pcodeinjectlib != (PcodeInjectLibrary *)0)
- delete pcodeinjectlib;
- if (commentdb != (CommentDatabase *)0)
- delete commentdb;
- if (stringManager != (StringManager *)0)
- delete stringManager;
- if (cpool != (ConstantPool *)0)
- delete cpool;
- if (context != (ContextDatabase *)0)
- delete context;
+ for(auto &model : protoModels)
+ delete model.second;
+
+ delete types;
+ delete translate;
+ delete loader;
+ delete pcodeinjectlib;
+ delete commentdb;
+ delete stringManager;
+ delete cpool;
+ delete context;
}
/// The Architecture maintains the set of prototype models that can
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/block.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/block.cc
index 63311a5ebf..d9a46fbedf 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/block.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/block.cc
@@ -1197,10 +1197,8 @@ void BlockGraph::markCopyBlock(FlowBlock *bl,uint4 fl)
void BlockGraph::clear(void)
{
- vector<FlowBlock *>::iterator iter;
-
- for(iter=list.begin();iter!=list.end();++iter)
- delete *iter;
+ for(auto *it : list)
+ delete it;
list.clear();
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/blockaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/blockaction.cc
index 1bb21f29d1..6645f67b11 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/blockaction.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/blockaction.cc
@@ -576,8 +576,8 @@ TraceDAG::BranchPoint::BranchPoint(BlockTrace *parenttrace)
TraceDAG::BranchPoint::~BranchPoint(void)
{
- for(int4 i=0;i<paths.size();++i)
- delete paths[i];
+ for(auto *path : paths)
+ delete path;
}
/// \param t is the parent BranchPoint
@@ -958,8 +958,8 @@ TraceDAG::TraceDAG(list<FloatingEdge> &lg)
TraceDAG::~TraceDAG(void)
{
- for(int4 i=0;i<branchlist.size();++i)
- delete branchlist[i];
+ for(auto *branch : branchlist)
+ delete branch;
}
/// Given the registered root FlowBlocks, create the initial (virtual) BranchPoint
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/comment.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/comment.cc
index d9d2000e55..c381aa27a3 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/comment.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/comment.cc
@@ -139,19 +139,15 @@ CommentDatabaseInternal::CommentDatabaseInternal(void)
CommentDatabaseInternal::~CommentDatabaseInternal(void)
{
- CommentSet::iterator iter;
-
- for(iter=commentset.begin();iter!=commentset.end();++iter)
- delete *iter;
+ for(auto *it : commentset)
+ delete it;
}
void CommentDatabaseInternal::clear(void)
{
- CommentSet::iterator iter;
-
- for(iter=commentset.begin();iter!=commentset.end();++iter)
- delete *iter;
+ for(auto *it : commentset)
+ delete it;
commentset.clear();
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/context.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/context.hh
index 79fbe1eff6..531643349c 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/context.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/context.hh
@@ -96,7 +96,7 @@ private:
int4 delayslot; // delayslot depth
public:
ParserContext(ContextCache *ccache,Translate *trans);
- ~ParserContext(void) { if (context != (uintm *)0) delete [] context; }
+ ~ParserContext(void) { delete [] context; }
uint1 *getBuffer(void) { return buf; }
void initialize(int4 maxstate,int4 maxparam,AddrSpace *spc);
int4 getParserState(void) const { return parsestate; }
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.hh
index f3fedca4be..4afb6aa5e3 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/cpool.hh
@@ -81,7 +81,7 @@ private:
int4 byteDataLen; ///< The number of bytes in the data for a string literal
public:
CPoolRecord(void) { type = (Datatype *)0; byteData = (uint1 *)0; } ///< Construct an empty record
- ~CPoolRecord(void) { if (byteData != (uint1 *)0) delete [] byteData; } ///< Destructor
+ ~CPoolRecord(void) { delete [] byteData; } ///< Destructor
uint4 getTag(void) const { return tag; } ///< Get the type of record
const string &getToken(void) const { return token; } ///< Get name of method or data-type
const uint1 *getByteData(void) const { return byteData; } ///< Get pointer to string literal data
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/database.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/database.cc
index 6a07f66f12..5311026aab 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/database.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/database.cc
@@ -549,9 +549,10 @@ FunctionSymbol::FunctionSymbol(Scope *sc,int4 size)
buildType();
}
-FunctionSymbol::~FunctionSymbol(void) {
- if (fd != (Funcdata *)0)
- delete fd;
+FunctionSymbol::~FunctionSymbol(void)
+
+{
+ delete fd;
}
Funcdata *FunctionSymbol::getFunction(void)
@@ -1182,11 +1183,8 @@ SymbolEntry *Scope::addMap(SymbolEntry &entry)
Scope::~Scope(void)
{
- ScopeMap::iterator iter = children.begin();
- while(iter != children.end()) {
- delete (*iter).second;
- ++iter;
- }
+ for (auto &it : children)
+ delete it.second;
}
/// Starting from \b this Scope, look for a Symbol with the given name.
@@ -1962,16 +1960,10 @@ ScopeInternal::ScopeInternal(uint8 id,const string &nm,Architecture *g, Scope *o
ScopeInternal::~ScopeInternal(void)
{
- vector<EntryMap *>::iterator iter1;
-
- for(iter1=maptable.begin();iter1!=maptable.end();++iter1)
- if ((*iter1) != (EntryMap *)0)
- delete *iter1;
-
- SymbolNameTree::iterator iter2;
-
- for(iter2=nametree.begin();iter2!=nametree.end();++iter2)
- delete *iter2;
+ for(auto *it : maptable)
+ delete it;
+ for(auto *it : nametree)
+ delete it;
}
void ScopeInternal::clear(void)
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/emulate.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/emulate.cc
index b26bf24d83..299495c47a 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/emulate.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/emulate.cc
@@ -341,10 +341,10 @@ EmulatePcodeCache::EmulatePcodeCache(Translate *t,MemoryState *s,BreakTable *b)
void EmulatePcodeCache::clearCache(void)
{
- for(int4 i=0;i<opcache.size();++i)
- delete opcache[i];
- for(int4 i=0;i<varcache.size();++i)
- delete varcache[i];
+ for(auto *op : opcache)
+ delete op;
+ for(auto *var : varcache)
+ delete var;
opcache.clear();
varcache.clear();
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/emulateutil.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/emulateutil.cc
index 73fcfec97f..eaf01b119c 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/emulateutil.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/emulateutil.cc
@@ -295,10 +295,10 @@ void EmulateSnippet::fallthruOp(void)
EmulateSnippet::~EmulateSnippet(void)
{
- for(int4 i=0;i<opList.size();++i)
- delete opList[i];
- for(int4 i=0;i<varList.size();++i)
- delete varList[i];
+ for(auto *op : opList)
+ delete op;
+ for(auto *var : varList)
+ delete var;
}
/// \brief Provide the caller with an emitter for building the p-code snippet
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
index 9701b1f798..aa9000b726 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
@@ -611,11 +611,8 @@ ParamListStandard::ParamListStandard(const ParamListStandard &op2)
ParamListStandard::~ParamListStandard(void)
{
- for(int4 i=0;i<resolverMap.size();++i) {
- ParamEntryResolver *resolver = resolverMap[i];
- if (resolver != (ParamEntryResolver *)0)
- delete resolver;
- }
+ for(auto *resolver : resolverMap)
+ delete resolver;
}
/// The entry must have a unique group.
@@ -2381,10 +2378,8 @@ ProtoModel::ProtoModel(const string &nm,const ProtoModel &op2)
ProtoModel::~ProtoModel(void)
{
- if (input != (ParamList *)0)
- delete input;
- if (output != (ParamList *)0)
- delete output;
+ delete input;
+ delete output;
}
/// Test whether one ProtoModel can substituted for another during FuncCallSpecs::deindirect
@@ -3142,13 +3137,9 @@ ProtoStoreSymbol::ProtoStoreSymbol(Scope *sc,const Address &usepoint)
ProtoStoreSymbol::~ProtoStoreSymbol(void)
{
- for(int4 i=0;i<inparam.size();++i) {
- ProtoParameter *param = inparam[i];
- if (param != (ProtoParameter *)0)
- delete param;
- }
- if (outparam != (ProtoParameter *)0)
- delete outparam;
+ for(auto *param : inparam)
+ delete param;
+ delete outparam;
}
/// Retrieve the specified ProtoParameter object, making sure it is a ParameterSymbol.
@@ -3164,8 +3155,7 @@ ParameterSymbol *ProtoStoreSymbol::getSymbolBacked(int4 i)
ParameterSymbol *res = dynamic_cast<ParameterSymbol *>(inparam[i]);
if (res != (ParameterSymbol *)0)
return res;
- if (inparam[i] != (ProtoParameter *)0)
- delete inparam[i];
+ delete inparam[i];
res = new ParameterSymbol();
inparam[i] = res;
return res;
@@ -3265,8 +3255,7 @@ ProtoParameter *ProtoStoreSymbol::getInput(int4 i)
ProtoParameter *ProtoStoreSymbol::setOutput(const ParameterPieces &piece)
{
- if (outparam != (ProtoParameter *)0)
- delete outparam;
+ delete outparam;
outparam = new ParameterBasic("",piece.addr,piece.type,piece.flags);
return outparam;
}
@@ -3326,13 +3315,9 @@ ProtoStoreInternal::ProtoStoreInternal(Datatype *vt)
ProtoStoreInternal::~ProtoStoreInternal(void)
{
- if (outparam != (ProtoParameter *)0)
- delete outparam;
- for(int4 i=0;i<inparam.size();++i) {
- ProtoParameter *param = inparam[i];
- if (param != (ProtoParameter *)0)
- delete param;
- }
+ delete outparam;
+ for(auto *param : inparam)
+ delete param;
}
ProtoParameter *ProtoStoreInternal::setInput(int4 i,const string &nm,const ParameterPieces &pieces)
@@ -3340,8 +3325,7 @@ ProtoParameter *ProtoStoreInternal::setInput(int4 i,const string &nm,const Param
{
while(inparam.size() <= i)
inparam.push_back((ProtoParameter *)0);
- if (inparam[i] != (ProtoParameter *)0)
- delete inparam[i];
+ delete inparam[i];
inparam[i] = new ParameterBasic(nm,pieces.addr,pieces.type,pieces.flags);
return inparam[i];
}
@@ -3351,8 +3335,7 @@ void ProtoStoreInternal::clearInput(int4 i)
{
int4 sz = inparam.size();
if (i>=sz) return;
- if (inparam[i] != (ProtoParameter *)0)
- delete inparam[i];
+ delete inparam[i];
inparam[i] = (ProtoParameter *)0;
for(int4 j=i+1;j<sz;++j) { // Renumber parameters with index > i
inparam[j-1] = inparam[j];
@@ -3365,10 +3348,8 @@ void ProtoStoreInternal::clearInput(int4 i)
void ProtoStoreInternal::clearAllInputs(void)
{
- for(int4 i=0;i<inparam.size();++i) {
- if (inparam[i] != (ProtoParameter *)0)
- delete inparam[i];
- }
+ for(auto *param : inparam)
+ delete param;
inparam.clear();
}
@@ -3389,8 +3370,7 @@ ProtoParameter *ProtoStoreInternal::getInput(int4 i)
ProtoParameter *ProtoStoreInternal::setOutput(const ParameterPieces &piece)
{
- if (outparam != (ProtoParameter *)0)
- delete outparam;
+ delete outparam;
outparam = new ParameterBasic("",piece.addr,piece.type,piece.flags);
return outparam;
}
@@ -3398,8 +3378,7 @@ ProtoParameter *ProtoStoreInternal::setOutput(const ParameterPieces &piece)
void ProtoStoreInternal::clearOutput(void)
{
- if (outparam != (ProtoParameter *)0)
- delete outparam;
+ delete outparam;
outparam = new ParameterBasic(voidtype);
}
@@ -3797,8 +3776,7 @@ void FuncProto::copy(const FuncProto &op2)
model = op2.model;
extrapop = op2.extrapop;
flags = op2.flags;
- if (store != (ProtoStore *)0)
- delete store;
+ delete store;
if (op2.store != (ProtoStore *)0)
store = op2.store->clone();
else
@@ -3904,8 +3882,7 @@ void FuncProto::setInternal(ProtoModel *m,Datatype *vt)
FuncProto::~FuncProto(void)
{
- if (store != (ProtoStore *)0)
- delete store;
+ delete store;
}
bool FuncProto::isInputLocked(void) const
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.hh
index 5ce115986e..1b229d371b 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata.hh
@@ -411,7 +411,7 @@ public:
void initActiveOutput(void); ///< Initialize \e return prototype recovery analysis
/// \brief Clear any analysis of the function's \e return prototype
void clearActiveOutput(void) {
- if (activeoutput != (ParamActive *)0) delete activeoutput;
+ delete activeoutput;
activeoutput = (ParamActive *)0;
}
ParamActive *getActiveOutput(void) const { return activeoutput; } ///< Get the \e return prototype recovery object
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.cc
index 9ec6788370..36cab1ede2 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ghidra_process.cc
@@ -232,10 +232,8 @@ void DeregisterProgram::rawAction(void)
{
#ifdef __REMOTE_SOCKET__
- if (ghidra_dcp != (IfaceStatus *)0)
- delete ghidra_dcp;
- if (remote != (RemoteSocket *)0)
- delete remote;
+ delete ghidra_dcp;
+ delete remote;
ghidra_dcp = (IfaceStatus *)0;
remote = (RemoteSocket *)0;
#endif
@@ -428,8 +426,7 @@ void SetOptions::loadParameters(void)
SetOptions::~SetOptions(void)
{
- if (decoder != (Decoder *)0)
- delete decoder;
+ delete decoder;
}
void SetOptions::rawAction(void)
@@ -488,9 +485,8 @@ int4 GhidraCapability::readCommand(istream &sin,ostream &out)
void GhidraCapability::shutDown(void)
{
- map<string,GhidraCommand *>::iterator iter;
- for(iter=commandmap.begin();iter!=commandmap.end();++iter)
- delete (*iter).second;
+ for(auto &it : commandmap)
+ delete it.second;
}
void GhidraDecompCapability::initialize(void)
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.cc
index 1690d7e2bf..16d2a42bff 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.cc
@@ -2703,45 +2703,36 @@ Datatype *CParse::oldEnum(const string &ident)
void CParse::clearAllocation(void)
{
- list<TypeDeclarator *>::iterator iter1;
-
- for(iter1=typedec_alloc.begin();iter1!=typedec_alloc.end();++iter1)
- delete *iter1;
+ for(auto *it : typedec_alloc)
+ delete it;
typedec_alloc.clear();
- list<TypeSpecifiers *>::iterator iter2;
- for(iter2=typespec_alloc.begin();iter2!=typespec_alloc.end();++iter2)
- delete *iter2;
+ for(auto *it : typespec_alloc)
+ delete it;
typespec_alloc.clear();
- list<vector<uint4> *>::iterator iter3;
- for(iter3=vecuint4_alloc.begin();iter3!=vecuint4_alloc.end();++iter3)
- delete *iter3;
+ for(auto *it : vecuint4_alloc)
+ delete it;
vecuint4_alloc.clear();
- list<vector<TypeDeclarator *> *>::iterator iter4;
- for(iter4=vecdec_alloc.begin();iter4!=vecdec_alloc.end();++iter4)
- delete *iter4;
+ for(auto *it : vecdec_alloc)
+ delete it;
vecdec_alloc.clear();
- list<string *>::iterator iter5;
- for(iter5=string_alloc.begin();iter5!=string_alloc.end();++iter5)
- delete *iter5;
+ for(auto *it : string_alloc)
+ delete it;
string_alloc.clear();
- list<uintb *>::iterator iter6;
- for(iter6=num_alloc.begin();iter6!=num_alloc.end();++iter6)
- delete *iter6;
+ for(auto *it : num_alloc)
+ delete it;
num_alloc.clear();
- list<Enumerator *>::iterator iter7;
- for(iter7=enum_alloc.begin();iter7!=enum_alloc.end();++iter7)
- delete *iter7;
+ for(auto *it : enum_alloc)
+ delete it;
enum_alloc.clear();
- list<vector<Enumerator *> *>::iterator iter8;
- for(iter8=vecenum_alloc.begin();iter8!=vecenum_alloc.end();++iter8)
- delete *iter8;
+ for(auto *it : vecenum_alloc)
+ delete it;
vecenum_alloc.clear();
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.y b/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.y
index c95526decb..08a59d3ccc 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.y
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/grammar.y
@@ -1160,45 +1160,36 @@ Datatype *CParse::oldEnum(const string &ident)
void CParse::clearAllocation(void)
{
- list<TypeDeclarator *>::iterator iter1;
-
- for(iter1=typedec_alloc.begin();iter1!=typedec_alloc.end();++iter1)
- delete *iter1;
+ for(auto *it : typedec_alloc)
+ delete it;
typedec_alloc.clear();
- list<TypeSpecifiers *>::iterator iter2;
- for(iter2=typespec_alloc.begin();iter2!=typespec_alloc.end();++iter2)
- delete *iter2;
+ for(auto *it : typespec_alloc)
+ delete it;
typespec_alloc.clear();
- list<vector<uint4> *>::iterator iter3;
- for(iter3=vecuint4_alloc.begin();iter3!=vecuint4_alloc.end();++iter3)
- delete *iter3;
+ for(auto *it : vecuint4_alloc)
+ delete it;
vecuint4_alloc.clear();
- list<vector<TypeDeclarator *> *>::iterator iter4;
- for(iter4=vecdec_alloc.begin();iter4!=vecdec_alloc.end();++iter4)
- delete *iter4;
+ for(auto *it : vecdec_alloc)
+ delete it;
vecdec_alloc.clear();
- list<string *>::iterator iter5;
- for(iter5=string_alloc.begin();iter5!=string_alloc.end();++iter5)
- delete *iter5;
+ for(auto *it : string_alloc)
+ delete it;
string_alloc.clear();
- list<uintb *>::iterator iter6;
- for(iter6=num_alloc.begin();iter6!=num_alloc.end();++iter6)
- delete *iter6;
+ for(auto *it : num_alloc)
+ delete it;
num_alloc.clear();
- list<Enumerator *>::iterator iter7;
- for(iter7=enum_alloc.begin();iter7!=enum_alloc.end();++iter7)
- delete *iter7;
+ for(auto *it : enum_alloc)
+ delete it;
enum_alloc.clear();
- list<vector<Enumerator *> *>::iterator iter8;
- for(iter8=vecenum_alloc.begin();iter8!=vecenum_alloc.end();++iter8)
- delete *iter8;
+ for(auto *it : vecenum_alloc)
+ delete it;
vecenum_alloc.clear();
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc
index 0237adb820..f96203b7d6 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/ifacedecomp.cc
@@ -237,20 +237,16 @@ IfaceDecompData::IfaceDecompData(void)
IfaceDecompData::~IfaceDecompData(void)
{
- if (cgraph != (CallGraph *)0)
- delete cgraph;
- if (conf != (Architecture *)0)
- delete conf;
- if (testCollection != (FunctionTestCollection *)0)
- delete testCollection;
+ delete cgraph;
+ delete conf;
+ delete testCollection;
// fd will get deleted with Database
}
void IfaceDecompData::allocateCallGraph(void)
{
- if (cgraph != (CallGraph *)0)
- delete cgraph;
+ delete cgraph;
cgraph = new CallGraph(conf);
}
@@ -270,8 +266,7 @@ void IfaceDecompData::abortFunction(ostream &s)
void IfaceDecompData::clearArchitecture(void)
{
- if (conf != (Architecture *)0)
- delete conf;
+ delete conf;
conf = (Architecture *)0;
fd = (Funcdata *)0;
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.cc
index e3abd636f3..bdff46870e 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/inject_sleigh.cc
@@ -22,15 +22,13 @@ namespace ghidra {
InjectContextSleigh::~InjectContextSleigh(void)
{
- if (pos != (ParserContext *)0)
- delete pos;
+ delete pos;
}
InjectPayloadSleigh::~InjectPayloadSleigh(void)
{
- if (tpl != (ConstructTpl *)0)
- delete tpl;
+ delete tpl;
}
InjectPayloadSleigh::InjectPayloadSleigh(const string &src,const string &nm,int4 tp)
@@ -204,8 +202,7 @@ ExecutablePcodeSleigh::ExecutablePcodeSleigh(Architecture *g,const string &src,c
ExecutablePcodeSleigh::~ExecutablePcodeSleigh(void)
{
- if (tpl != (ConstructTpl *)0)
- delete tpl;
+ delete tpl;
}
void ExecutablePcodeSleigh::inject(InjectContext &context,PcodeEmit &emit) const
@@ -255,9 +252,8 @@ void ExecutablePcodeSleigh::printTemplate(ostream &s) const
InjectPayloadDynamic::~InjectPayloadDynamic(void)
{
- map<Address,Document *>::iterator iter;
- for(iter=addrMap.begin();iter!=addrMap.end();++iter)
- delete (*iter).second;
+ for(auto &it : addrMap)
+ delete it.second;
}
void InjectPayloadDynamic::decodeEntry(Decoder &decoder)
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/interface.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/interface.cc
index 85f5f91df3..d0764370c8 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/interface.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/interface.cc
@@ -57,23 +57,14 @@ RemoteSocket::RemoteSocket(void)
void RemoteSocket::close(void)
{
- if (inStream != (istream *)0) {
- delete inStream;
- inStream = (istream *)0;
- }
- if (outStream != (ostream *)0) {
- delete outStream;
- outStream = (ostream *)0;
- }
- if (inbuf != (basic_filebuf<char> *)0) {
- // Destroying the buffer should automatically close the socket
- delete inbuf;
- inbuf = (basic_filebuf<char> *)0;
- }
- if (outbuf != (basic_filebuf<char> *)0) {
- delete outbuf;
- outbuf = (basic_filebuf<char> *)0;
- }
+ delete inStream;
+ inStream = (istream *)0;
+ delete outStream;
+ outStream = (ostream *)0;
+ delete inbuf;
+ inbuf = (basic_filebuf<char> *)0;
+ delete outbuf;
+ outbuf = (basic_filebuf<char> *)0;
isOpen = false;
}
@@ -256,18 +247,14 @@ void IfaceStatus::wordsToString(string &res,const vector<string> &list)
IfaceStatus::~IfaceStatus(void)
{
- if (optr != fileoptr) {
- ((ofstream *)fileoptr)->close();
+ if (optr != fileoptr)
delete fileoptr;
- }
while(!promptstack.empty())
popScript();
for(int4 i=0;i<comlist.size();++i)
delete comlist[i];
- map<string,IfaceData *>::const_iterator iter;
- for(iter=datamap.begin();iter!=datamap.end();++iter)
- if ((*iter).second != (IfaceData *)0)
- delete (*iter).second;
+ for(auto &it : datamap)
+ delete it.second;
}
/// \brief Register a command with this interface
@@ -598,7 +585,6 @@ void IfcClosefile::execute(istream &s)
{
if (status->optr == status->fileoptr)
throw IfaceExecutionError("No file open");
- ((ofstream *)status->fileoptr)->close();
delete status->fileoptr;
status->fileoptr = status->optr;
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc
index e41c7b3488..0fc8b03b22 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/jumptable.cc
@@ -1394,8 +1394,7 @@ bool JumpBasic::foldInOneGuard(Funcdata *fd,GuardRecord &guard,JumpTable *jump)
JumpBasic::~JumpBasic(void)
{
- if (jrange != (JumpValuesRange *)0)
- delete jrange;
+ delete jrange;
}
bool JumpBasic::recoverModel(Funcdata *fd,PcodeOp *indop,uint4 matchsize,uint4 maxtablesize)
@@ -1604,10 +1603,8 @@ JumpModel *JumpBasic::clone(JumpTable *jt) const
void JumpBasic::clear(void)
{
- if (jrange != (JumpValuesRange *)0) {
- delete jrange;
- jrange = (JumpValuesRange *)0;
- }
+ delete jrange;
+ jrange = (JumpValuesRange *)0;
pathMeld.clear();
selectguards.clear();
normalvn = (Varnode *)0;
@@ -2381,10 +2378,8 @@ JumpTable::JumpTable(const JumpTable *op2)
JumpTable::~JumpTable(void)
{
- if (jmodel != (JumpModel *)0)
- delete jmodel;
- if (origmodel != (JumpModel *)0)
- delete origmodel;
+ delete jmodel;
+ delete origmodel;
}
/// \brief Return the number of address table entries that target the given basic-block
@@ -2422,8 +2417,7 @@ bool JumpTable::isOverride(void) const
void JumpTable::setOverride(const vector<Address> &addrtable,const Address &naddr,uintb h,uintb sv)
{
- if (jmodel != (JumpModel *)0)
- delete jmodel;
+ delete jmodel;
JumpBasicOverride *override;
jmodel = override = new JumpBasicOverride(this);
@@ -2609,8 +2603,7 @@ void JumpTable::recoverAddresses(Funcdata *fd)
void JumpTable::recoverMultistage(Funcdata *fd)
{
- if (origmodel != (JumpModel *)0)
- delete origmodel;
+ delete origmodel;
origmodel = jmodel;
jmodel = (JumpModel *)0;
@@ -2621,26 +2614,21 @@ void JumpTable::recoverMultistage(Funcdata *fd)
recoverAddresses(fd);
}
catch(JumptableThunkError &err) {
- if (jmodel != (JumpModel *)0)
- delete jmodel;
+ delete jmodel;
jmodel = origmodel;
origmodel = (JumpModel *)0;
addresstable = oldaddresstable;
fd->warning("Second-stage recovery error",indirect->getAddr());
}
catch(LowlevelError &err) {
- if (jmodel != (JumpModel *)0)
- delete jmodel;
+ delete jmodel;
jmodel = origmodel;
origmodel = (JumpModel *)0;
addresstable = oldaddresstable;
fd->warning("Second-stage recovery error",indirect->getAddr());
}
recoverystage = 2;
- if (origmodel != (JumpModel *)0) { // Keep the new model if it was created successfully
- delete origmodel;
- origmodel = (JumpModel *)0;
- }
+ delete origmodel;
}
/// This is run assuming the address table has already been recovered, via recoverAddresses() in another
@@ -2658,8 +2646,7 @@ bool JumpTable::recoverLabels(Funcdata *fd)
// Unless the model is an override, move model (created on a flow copy) so we can create a current instance
if (jmodel != (JumpModel *)0) {
- if (origmodel != (JumpModel *)0)
- delete origmodel;
+ delete origmodel;
if (!jmodel->isOverride()) {
origmodel = jmodel;
jmodel = (JumpModel *)0;
@@ -2692,10 +2679,8 @@ bool JumpTable::recoverLabels(Funcdata *fd)
trivialSwitchOver();
jmodel->buildLabels(fd,addresstable,label,origmodel);
}
- if (origmodel != (JumpModel *)0) {
- delete origmodel;
- origmodel = (JumpModel *)0;
- }
+ delete origmodel;
+ origmodel = (JumpModel *)0;
return multistagerestart;
}
@@ -2704,10 +2689,8 @@ bool JumpTable::recoverLabels(Funcdata *fd)
void JumpTable::clear(void)
{
- if (origmodel != (JumpModel *)0) {
- delete origmodel;
- origmodel = (JumpModel *)0;
- }
+ delete origmodel;
+ origmodel = (JumpModel *)0;
if (jmodel->isOverride())
jmodel->clear();
else {
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage.cc
index 87bcb5de89..d17dc57296 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage.cc
@@ -48,10 +48,7 @@ RawLoadImage::RawLoadImage(const string &f) : LoadImage(f)
RawLoadImage::~RawLoadImage(void)
{
- if (thefile != (ifstream *)0) {
- thefile->close();
- delete thefile;
- }
+ delete thefile;
}
/// The file is opened and its size immediately recovered.
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_bfd.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_bfd.cc
index 477c17e817..085c9089ef 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_bfd.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/loadimage_bfd.cc
@@ -41,8 +41,7 @@ LoadImageBfd::LoadImageBfd(const string &f,const string &t) : LoadImage(f)
LoadImageBfd::~LoadImageBfd(void)
{
- if (symbol_table != (asymbol **)0)