Jacek Caban (@jacek) commented about dlls/vbscript/global.c:
str = V_BSTR(&data[i]);
if (i > lbound) {
string_len = SysStringLen(string);
tmp = SysAllocStringLen(string, string_len + delimiter_len);
memcpy(tmp + string_len, delimiter, delimiter_len * sizeof(WCHAR));
SysFreeString(string);
string = tmp;
}
string_len = SysStringLen(string);
str_len = SysStringLen(str);
tmp = SysAllocStringLen(string, string_len + str_len);
memcpy(tmp + string_len, str, str_len * sizeof(WCHAR));
SysFreeString(string);
string = tmp;
That's potentially a lot of string reallocation. A cleaner and more efficient approach would be to first convert all necessary strings and store the results as pointers in an array and calculate the required length. Then, allocate the output buffer, and copy all the joined strings into it.