MantisBT - Doomseeker
View Issue Details
0003801Doomseeker[All Projects] Cleanuppublic2020-06-07 01:312020-06-17 08:24
WubTheCaptain 
WubTheCaptain 
nonetweakalways
resolvedsuspended 
1.3.1 
 
0003801: new/delete used instead of std::unique_ptr/std::make_unique
I tried to write a coherent description here, but I couldn't?

std::unique_ptr seems to be a better practice, instead of new/delete. Since C++11. Doomseeker (and Wadseeker) uses C++98 style new/delete.
And std::make_unique seems even better. Since C++14.

Let's modernize?
$ grep -r 'new ' src/ | wc -l
586
$ grep -r 'new\[\]' src/ | wc -l
0
$ grep -r 'delete\[\]' src/ | wc -l
8
$ grep -r 'delete ' src/ | wc -l
180
$ grep -r 'unique_ptr' src/ | wc -l
0
https://en.cppreference.com/w/cpp/memory/unique_ptr [^]
https://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique [^]
https://isocpp.org/wiki/faq/freestore-mgmt [^]
https://clang.llvm.org/extra/clang-tidy/checks/modernize-make-unique.html [^]
No tags attached.
child of 0003803confirmed  C++11 support 
child of 0003804acknowledged  C++14 support 
Issue History
2020-06-07 01:31WubTheCaptainNew Issue
2020-06-07 02:26WubTheCaptainSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=13119#r13119
2020-06-07 02:29WubTheCaptainRelationship addedchild of 0003803
2020-06-07 02:32WubTheCaptainRelationship addedchild of 0003804
2020-06-07 19:25Pol MNote Added: 0021376
2020-06-07 19:25Pol MAssigned To => Pol M
2020-06-07 19:25Pol MStatusnew => confirmed
2020-06-07 19:40Pol MAssigned ToPol M =>
2020-06-16 14:22WubTheCaptainNote Added: 0021465
2020-06-16 14:22WubTheCaptainStatusconfirmed => acknowledged
2020-06-16 23:23Pol MNote Added: 0021466
2020-06-17 08:24WubTheCaptainStatusacknowledged => resolved
2020-06-17 08:24WubTheCaptainResolutionopen => suspended
2020-06-17 08:24WubTheCaptainAssigned To => WubTheCaptain

Notes
(0021376)
Pol M   
2020-06-07 19:25   
While this is a good idea, libraries shouldn't be touched. Also, while smart pointers will work, you could look for alternatives in each case. For instance:

diff --git a/src/wadseeker/zip/unarchive.cpp b/src/wadseeker/zip/unarchive.cpp
index 55f0a04a..9aeff22a 100644
--- a/src/wadseeker/zip/unarchive.cpp
+++ b/src/wadseeker/zip/unarchive.cpp
@@ -62,9 +62,8 @@ public:
                        position = bufferedData.size();
                        stream->seek(bufferedData.size());
                        QIODevice::seek(bufferedData.size());
- char *tmp = new char[neededDataSize];
- read(tmp, neededDataSize);
- delete[] tmp;
+ QVector<char> tmp(neededDataSize);
+ read(tmp.data(), neededDataSize);
                }
                else
                {
(0021465)
WubTheCaptain   
2020-06-16 14:22   
Should we use std::unique_ptr or Qt's QScopedPointer?
Mumble decided to go with STL pointers.https://github.com/mumble-voip/mumble/issues/3937 [^]
(0021466)
Pol M   
2020-06-16 23:23   
Since we are already using QScopedPointer, we should stick to that :)