12
12
#define GSS_C_REPLAY_FLAG 4
13
13
#define GSS_C_SEQUENCE_FLAG 8
14
14
15
- const wchar_t * to_wstring (const char *bytes) {
16
- unsigned int sizeOfStr = MultiByteToWideChar (CP_UTF8, 0 , bytes, -1 , NULL , 0 );
17
- wchar_t *output = new wchar_t [sizeOfStr];
18
- MultiByteToWideChar (CP_UTF8, 0 , bytes, -1 , output, sizeOfStr);
19
- return output;
15
+ const std::wstring to_wstring (const char *bytes) {
16
+ DWORD sizeOfStr = MultiByteToWideChar (CP_UTF8, 0 , bytes, -1 , NULL , 0 );
17
+ assert (sizeOfStr > 0 );
18
+ std::wstring arg (sizeOfStr, ' \0 ' );
19
+ DWORD result = MultiByteToWideChar (CP_UTF8, 0 , bytes, -1 , &arg[0 ], sizeOfStr);
20
+ assert (result > 0 );
21
+ arg.resize (result - 1 );
22
+ return arg;
20
23
}
21
24
22
25
NAN_INLINE std::wstring WStringOptionValue (v8::Local<v8::Object> options, const char * _key) {
@@ -31,7 +34,7 @@ NAN_INLINE std::wstring WStringOptionValue(v8::Local<v8::Object> options, const
31
34
return std::wstring ();
32
35
}
33
36
34
- return std::wstring ( to_wstring (*(Nan::Utf8String (value) )));
37
+ return to_wstring (*(Nan::Utf8String (value)));
35
38
}
36
39
37
40
// / KerberosClient
@@ -137,7 +140,7 @@ NAN_METHOD(KerberosServer::Step) {
137
140
138
141
// / Global Methods
139
142
NAN_METHOD (InitializeClient) {
140
- std::wstring service ( to_wstring (*(Nan::Utf8String (info[0 ]) )));
143
+ std::wstring service = to_wstring (*(Nan::Utf8String (info[0 ])));
141
144
v8::Local<v8::Object> options = Nan::To<v8::Object>(info[1 ]).ToLocalChecked ();
142
145
Nan::Callback* callback = new Nan::Callback (Nan::To<v8::Function>(info[2 ]).ToLocalChecked ());
143
146
0 commit comments