Rename String::resize to resize_uninitialized, to better communicate to callers that new characters must be initialized.

This commit is contained in:
Lukas Tenbrink
2025-05-28 20:33:21 +02:00
parent 51b0379e55
commit b13a0e1834
26 changed files with 103 additions and 98 deletions

View File

@ -616,7 +616,7 @@ void DisplayServerWindows::_thread_fd_monitor(void *p_ud) {
if (dir.is_relative_path() || dir == ".") {
Char16String current_dir_name;
size_t str_len = GetCurrentDirectoryW(0, nullptr);
current_dir_name.resize(str_len + 1);
current_dir_name.resize_uninitialized(str_len + 1);
GetCurrentDirectoryW(current_dir_name.size(), (LPWSTR)current_dir_name.ptrw());
if (dir == ".") {
dir = String::utf16((const char16_t *)current_dir_name.get_data()).trim_prefix(R"(\\?\)").replace_char('\\', '/');
@ -3390,7 +3390,7 @@ static INT_PTR input_text_dialog_cmd_proc(HWND hWnd, UINT code, WPARAM wParam, L
ERR_FAIL_NULL_V(text_edit, false);
Char16String text;
text.resize(GetWindowTextLengthW(text_edit) + 1);
text.resize_uninitialized(GetWindowTextLengthW(text_edit) + 1);
GetWindowTextW(text_edit, (LPWSTR)text.get_data(), text.size());
const Callable *callback = (const Callable *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);

View File

@ -41,7 +41,7 @@
static String create_temp_dir() {
Char16String buf;
int bufsize = GetTempPathW(0, nullptr) + 1;
buf.resize(bufsize);
buf.resize_uninitialized(bufsize);
if (GetTempPathW(bufsize, (LPWSTR)buf.ptrw()) == 0) {
return "";
}
@ -158,7 +158,7 @@ HRESULT DropTargetWindows::handle_hdrop_format(Vector<String> *p_files, IDataObj
for (int i = 0; i < fcount; i++) {
int buffsize = DragQueryFileW(hDropInfo, i, nullptr, 0);
buf.resize(buffsize + 1);
buf.resize_uninitialized(buffsize + 1);
if (DragQueryFileW(hDropInfo, i, (LPWSTR)buf.ptrw(), buffsize + 1) == 0) {
res = E_UNEXPECTED;
goto cleanup;

View File

@ -53,7 +53,7 @@ static String fix_path(const String &p_path) {
if (p_path.is_relative_path()) {
Char16String current_dir_name;
size_t str_len = GetCurrentDirectoryW(0, nullptr);
current_dir_name.resize(str_len + 1);
current_dir_name.resize_uninitialized(str_len + 1);
GetCurrentDirectoryW(current_dir_name.size(), (LPWSTR)current_dir_name.ptrw());
path = String::utf16((const char16_t *)current_dir_name.get_data()).trim_prefix(R"(\\?\)").replace_char('\\', '/').path_join(path);
}

View File

@ -574,7 +574,7 @@ int NativeMenuWindows::find_item_index_with_text(const RID &p_rid, const String
if (GetMenuItemInfoW(md->menu, i, true, &item)) {
item.cch++;
Char16String str;
str.resize(item.cch);
str.resize_uninitialized(item.cch);
item.dwTypeData = (LPWSTR)str.ptrw();
if (GetMenuItemInfoW(md->menu, i, true, &item)) {
if (String::utf16((const char16_t *)str.get_data()) == p_text) {
@ -728,7 +728,7 @@ String NativeMenuWindows::get_item_text(const RID &p_rid, int p_idx) const {
if (GetMenuItemInfoW(md->menu, p_idx, true, &item)) {
item.cch++;
Char16String str;
str.resize(item.cch);
str.resize_uninitialized(item.cch);
item.dwTypeData = (LPWSTR)str.ptrw();
if (GetMenuItemInfoW(md->menu, p_idx, true, &item)) {
return String::utf16((const char16_t *)str.get_data());

View File

@ -111,7 +111,7 @@ static String fix_path(const String &p_path) {
if (p_path.is_relative_path()) {
Char16String current_dir_name;
size_t str_len = GetCurrentDirectoryW(0, nullptr);
current_dir_name.resize(str_len + 1);
current_dir_name.resize_uninitialized(str_len + 1);
GetCurrentDirectoryW(current_dir_name.size(), (LPWSTR)current_dir_name.ptrw());
path = String::utf16((const char16_t *)current_dir_name.get_data()).trim_prefix(R"(\\?\)").replace_char('\\', '/').path_join(path);
}
@ -1280,12 +1280,12 @@ Dictionary OS_Windows::execute_with_pipe(const String &p_path, const List<String
Char16String current_dir_name;
size_t str_len = GetCurrentDirectoryW(0, nullptr);
current_dir_name.resize(str_len + 1);
current_dir_name.resize_uninitialized(str_len + 1);
GetCurrentDirectoryW(current_dir_name.size(), (LPWSTR)current_dir_name.ptrw());
if (current_dir_name.size() >= MAX_PATH) {
Char16String current_short_dir_name;
str_len = GetShortPathNameW((LPCWSTR)current_dir_name.ptr(), nullptr, 0);
current_short_dir_name.resize(str_len);
current_short_dir_name.resize_uninitialized(str_len);
GetShortPathNameW((LPCWSTR)current_dir_name.ptr(), (LPWSTR)current_short_dir_name.ptrw(), current_short_dir_name.size());
current_dir_name = current_short_dir_name;
}
@ -1386,12 +1386,12 @@ Error OS_Windows::execute(const String &p_path, const List<String> &p_arguments,
Char16String current_dir_name;
size_t str_len = GetCurrentDirectoryW(0, nullptr);
current_dir_name.resize(str_len + 1);
current_dir_name.resize_uninitialized(str_len + 1);
GetCurrentDirectoryW(current_dir_name.size(), (LPWSTR)current_dir_name.ptrw());
if (current_dir_name.size() >= MAX_PATH) {
Char16String current_short_dir_name;
str_len = GetShortPathNameW((LPCWSTR)current_dir_name.ptr(), nullptr, 0);
current_short_dir_name.resize(str_len);
current_short_dir_name.resize_uninitialized(str_len);
GetShortPathNameW((LPCWSTR)current_dir_name.ptr(), (LPWSTR)current_short_dir_name.ptrw(), current_short_dir_name.size());
current_dir_name = current_short_dir_name;
}
@ -1485,12 +1485,12 @@ Error OS_Windows::create_process(const String &p_path, const List<String> &p_arg
Char16String current_dir_name;
size_t str_len = GetCurrentDirectoryW(0, nullptr);
current_dir_name.resize(str_len + 1);
current_dir_name.resize_uninitialized(str_len + 1);
GetCurrentDirectoryW(current_dir_name.size(), (LPWSTR)current_dir_name.ptrw());
if (current_dir_name.size() >= MAX_PATH) {
Char16String current_short_dir_name;
str_len = GetShortPathNameW((LPCWSTR)current_dir_name.ptr(), nullptr, 0);
current_short_dir_name.resize(str_len);
current_short_dir_name.resize_uninitialized(str_len);
GetShortPathNameW((LPCWSTR)current_dir_name.ptr(), (LPWSTR)current_short_dir_name.ptrw(), current_short_dir_name.size());
current_dir_name = current_short_dir_name;
}
@ -1626,7 +1626,7 @@ Vector<String> OS_Windows::get_system_fonts() const {
hr = family_names->GetStringLength(index, &length);
ERR_CONTINUE(FAILED(hr));
name.resize(length + 1);
name.resize_uninitialized(length + 1);
hr = family_names->GetString(index, (WCHAR *)name.ptrw(), length + 1);
ERR_CONTINUE(FAILED(hr));
@ -2664,12 +2664,12 @@ OS_Windows::OS_Windows(HINSTANCE _hInstance) {
// Reset CWD to ensure long path is used.
Char16String current_dir_name;
size_t str_len = GetCurrentDirectoryW(0, nullptr);
current_dir_name.resize(str_len + 1);
current_dir_name.resize_uninitialized(str_len + 1);
GetCurrentDirectoryW(current_dir_name.size(), (LPWSTR)current_dir_name.ptrw());
Char16String new_current_dir_name;
str_len = GetLongPathNameW((LPCWSTR)current_dir_name.get_data(), nullptr, 0);
new_current_dir_name.resize(str_len + 1);
new_current_dir_name.resize_uninitialized(str_len + 1);
GetLongPathNameW((LPCWSTR)current_dir_name.get_data(), (LPWSTR)new_current_dir_name.ptrw(), new_current_dir_name.size());
SetCurrentDirectoryW((LPCWSTR)new_current_dir_name.get_data());