-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
Use std::unique_ptr<> instead of manually deleting the object and std::vector<> instead of manually allocating and deleting the buffers. No real changes.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ | |
#include "wx/mimetype.h" | ||
#include "wx/vector.h" | ||
|
||
#include <memory> | ||
|
||
class XRCWidgetData | ||
{ | ||
public: | ||
|
@@ -620,8 +622,8 @@ static wxString FileToCppArray(wxString filename, int num) | |
// we cannot use string literals because MSVC is dumb wannabe compiler | ||
// with arbitrary limitation to 2048 strings :( | ||
|
||
unsigned char *buffer = new unsigned char[lng]; | ||
file.Read(buffer, lng); | ||
std::vector<unsigned char> buffer(lng); | ||
file.Read(&buffer[0], lng); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
vadz
Author
Contributor
|
||
|
||
for (size_t i = 0, linelng = 0; i < lng; i++) | ||
{ | ||
|
@@ -636,8 +638,6 @@ static wxString FileToCppArray(wxString filename, int num) | |
linelng += tmp.length()+1; | ||
} | ||
|
||
delete[] buffer; | ||
|
||
output += wxT("};\n\n"); | ||
|
||
return output; | ||
|
@@ -711,12 +711,10 @@ void XmlResApp::MakePackageCPP(const wxArrayString& flist) | |
#if wxUSE_MIMETYPE | ||
else | ||
{ | ||
wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(ext); | ||
std::unique_ptr<wxFileType> | ||
ft{wxTheMimeTypesManager->GetFileTypeFromExtension(ext)}; | ||
if ( ft ) | ||
{ | ||
ft->GetMimeType(&mime); | ||
delete ft; | ||
} | ||
} | ||
#endif // wxUSE_MIMETYPE | ||
|
||
|
@@ -776,8 +774,8 @@ static wxString FileToPythonArray(wxString filename, int num) | |
snum.Printf(wxT("%i"), num); | ||
output = " xml_res_file_" + snum + " = '''\\\n"; | ||
|
||
unsigned char *buffer = new unsigned char[lng]; | ||
file.Read(buffer, lng); | ||
std::vector<unsigned char> buffer(lng); | ||
file.Read(&buffer[0], lng); | ||
|
||
for (size_t i = 0, linelng = 0; i < lng; i++) | ||
{ | ||
|
@@ -802,8 +800,6 @@ static wxString FileToPythonArray(wxString filename, int num) | |
linelng += tmp.length(); | ||
} | ||
|
||
delete[] buffer; | ||
|
||
output += wxT("'''\n\n"); | ||
|
||
return output; | ||
|
Thank you for the update !! :)
I think that f
lng
is zero,&buffer [0]
may trigger (at runtime) failed sanity checks with some debug versions of some implementations of STL.I remember this when
#define
-ing_STLP_DEBUG
with STLport.But I think that such checks are valid, because (as per https://timsong-cpp.github.io/cppwp/n4861/sequence.reqmts#14 -- the row with
a[n]
near the bottom of the table) evaluating&v [0]
theoretically implies dereferencingv.begin ()
, which in the case of an empty vector is a non-dereferenceable iterator.May I suggest replacing
&buffer [0]
withbuffer.data ()
(which is the same as&buffer [0]
except that it is also safe in the case of empty vectors), please ?