Make sure strings are null-terminated (resolve #1441)

This commit is contained in:
Joshua Granick
2021-01-04 11:34:54 -08:00
parent ccd9dca6e1
commit 20baa3ba6e
3 changed files with 18 additions and 11 deletions

View File

@@ -2671,8 +2671,9 @@ namespace lime {
if (model) {
int size = std::wcslen (model->c_str ());
char* result = (char*)malloc (size);
char* result = (char*)malloc (size + 1);
std::wcstombs (result, model->c_str (), size);
result[size] = '\0';
delete model;
return (vbyte*)result;
@@ -2714,8 +2715,9 @@ namespace lime {
if (vendor) {
int size = std::wcslen (vendor->c_str ());
char* result = (char*)malloc (size);
char* result = (char*)malloc (size + 1);
std::wcstombs (result, vendor->c_str (), size);
result[size] = '\0';
delete vendor;
return (vbyte*)result;
@@ -2757,8 +2759,9 @@ namespace lime {
if (path) {
int size = std::wcslen (path->c_str ());
char* result = (char*)malloc (size);
char* result = (char*)malloc (size + 1);
std::wcstombs (result, path->c_str (), size);
result[size] = '\0';
delete path;
return (vbyte*)result;
@@ -2850,8 +2853,9 @@ namespace lime {
if (label) {
int size = std::wcslen (label->c_str ());
char* result = (char*)malloc (size);
char* result = (char*)malloc (size + 1);
std::wcstombs (result, label->c_str (), size);
result[size] = '\0';
delete label;
return (vbyte*)result;
@@ -2893,8 +2897,9 @@ namespace lime {
if (name) {
int size = std::wcslen (name->c_str ());
char* result = (char*)malloc (size);
char* result = (char*)malloc (size + 1);
std::wcstombs (result, name->c_str (), size);
result[size] = '\0';
delete name;
return (vbyte*)result;
@@ -2936,8 +2941,9 @@ namespace lime {
if (version) {
int size = std::wcslen (version->c_str ());
char* result = (char*)malloc (size);
char* result = (char*)malloc (size + 1);
std::wcstombs (result, version->c_str (), size);
result[size] = '\0';
delete version;
return (vbyte*)result;

View File

@@ -140,7 +140,7 @@ namespace lime {
char folderPath[MAX_PATH] = "";
SHGetFolderPath (NULL, CSIDL_DESKTOPDIRECTORY, NULL, SHGFP_TYPE_CURRENT, folderPath);
WIN_StringToUTF8 (folderPath);
//WIN_StringToUTF8 (folderPath);
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
result = new std::wstring (converter.from_bytes (folderPath));
@@ -177,7 +177,7 @@ namespace lime {
char folderPath[MAX_PATH] = "";
SHGetFolderPath (NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, folderPath);
WIN_StringToUTF8 (folderPath);
//WIN_StringToUTF8 (folderPath);
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
result = new std::wstring (converter.from_bytes (folderPath));
@@ -215,7 +215,7 @@ namespace lime {
char folderPath[MAX_PATH] = "";
SHGetFolderPath (NULL, CSIDL_FONTS, NULL, SHGFP_TYPE_CURRENT, folderPath);
WIN_StringToUTF8 (folderPath);
//WIN_StringToUTF8 (folderPath);
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
result = new std::wstring (converter.from_bytes (folderPath));
@@ -255,7 +255,7 @@ namespace lime {
char folderPath[MAX_PATH] = "";
SHGetFolderPath (NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, folderPath);
WIN_StringToUTF8 (folderPath);
//WIN_StringToUTF8 (folderPath);
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
result = new std::wstring (converter.from_bytes (folderPath));

View File

@@ -14,8 +14,9 @@ namespace lime {
if (!source) return NULL;
int size = std::wcslen (source->c_str ());
char* temp = (char*)malloc (size);
char* temp = (char*)malloc (size + 1);
std::wcstombs (temp, source->c_str (), size);
temp[size] = '\0';
std::string* data = new std::string (temp);
free (temp);