Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

shellext: fix potential heap corruption bug with new[] not paired with delete[]

Array new (new[]) must be paired with array delete (delete[]), or
something nasty will happen at runtime.

Using std::vector instead.

Changeset 51bee82d4b6f

Parent 4758fe7fce44

by Adrian Buehlmann

Changes to one file · Browse files at 51bee82d4b6f Showing diff from parent 4758fe7fce44 Diff from another changeset...

 
17
18
19
20
 
21
22
23
 
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
 
17
18
19
 
20
21
22
23
 
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
@@ -17,7 +17,7 @@
   #include "StringUtils.h"   -#include <memory> +#include <vector>      // Quotes a string @@ -31,36 +31,39 @@
 // Convert Unicode string to multibyte string  std::string WideToMultibyte(const std::wstring& wide, UINT CodePage)  { - char* narrow = NULL;   // Determine length of string   int ret = WideCharToMultiByte(   CodePage, 0, wide.c_str(), static_cast<int>(wide.length()),   NULL, 0, NULL, NULL   ); - narrow = new char[ret + 1]; - std::auto_ptr<char> free_narrow(narrow); + + std::vector<CHAR> narrow(ret + 1); +   ret = WideCharToMultiByte(   CodePage, 0, wide.c_str(), static_cast<int>(wide.length()), - narrow, ret, NULL, NULL + &narrow[0], ret, NULL, NULL   );   narrow[ret] = '\0'; - return narrow; + + return &narrow[0];  }      // Convert multibyte string to Unicode string  std::wstring MultibyteToWide(const std::string& multibyte, UINT CodePage)  { - wchar_t* wide = NULL;   int ret = MultiByteToWideChar(   CodePage, 0, multibyte.c_str(),   static_cast<int>(multibyte.length()), 0, 0   ); - wide = new wchar_t[ret + 1]; - std::auto_ptr<wchar_t> free_narrow(wide); + + std::vector<wchar_t> wide(ret + 1); +   ret = MultiByteToWideChar(   CodePage, 0, multibyte.c_str(), - static_cast<int>(multibyte.length()), wide, ret); + static_cast<int>(multibyte.length()), &wide[0], ret + );   wide[ret] = L'\0'; - return wide; + + return &wide[0];  }