Skip to content

Commit

Permalink
Make sure strings are null-terminated (resolve #1441)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgranick committed Jan 4, 2021
1 parent ccd9dca commit 20baa3b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
18 changes: 12 additions & 6 deletions project/src/ExternalInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions project/src/backend/sdl/SDLSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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));

Expand Down
3 changes: 2 additions & 1 deletion project/src/ui/FileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 20baa3b

Please sign in to comment.