Skip to content

Commit 1719f8e

Browse files
committed
Merge pull request godotengine#99834 from kiroxas/passLengthToParseUTF8
Ensure `parse_utf8` has length of string passed in when available
2 parents e5d62fa + 83d4bde commit 1719f8e

File tree

10 files changed

+13
-15
lines changed

10 files changed

+13
-15
lines changed

core/config/project_settings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ Error ProjectSettings::_load_settings_binary(const String &p_path) {
749749
cs[slen] = 0;
750750
f->get_buffer((uint8_t *)cs.ptr(), slen);
751751
String key;
752-
key.parse_utf8(cs.ptr());
752+
key.parse_utf8(cs.ptr(), slen);
753753

754754
uint32_t vlen = f->get_32();
755755
Vector<uint8_t> d;

core/io/file_access.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ String FileAccess::get_as_utf8_string(bool p_skip_cr) const {
565565
w[len] = 0;
566566

567567
String s;
568-
s.parse_utf8((const char *)w, -1, p_skip_cr);
568+
s.parse_utf8((const char *)w, len, p_skip_cr);
569569
return s;
570570
}
571571

@@ -724,7 +724,7 @@ String FileAccess::get_pascal_string() {
724724
cs[sl] = 0;
725725

726726
String ret;
727-
ret.parse_utf8(cs.ptr());
727+
ret.parse_utf8(cs.ptr(), sl);
728728
return ret;
729729
}
730730

core/io/file_access_pack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files,
309309
cs[sl] = 0;
310310

311311
String path;
312-
path.parse_utf8(cs.ptr());
312+
path.parse_utf8(cs.ptr(), sl);
313313

314314
uint64_t ofs = f->get_64();
315315
uint64_t size = f->get_64();

core/io/http_client_tcp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ Error HTTPClientTCP::poll() {
484484
// End of response, parse.
485485
response_str.push_back(0);
486486
String response;
487-
response.parse_utf8((const char *)response_str.ptr());
487+
response.parse_utf8((const char *)response_str.ptr(), response_str.size());
488488
Vector<String> responses = response.split("\n");
489489
body_size = -1;
490490
chunked = false;

core/io/resource_format_binary.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ StringName ResourceLoaderBinary::_get_string() {
165165
}
166166
f->get_buffer((uint8_t *)&str_buf[0], len);
167167
String s;
168-
s.parse_utf8(&str_buf[0]);
168+
s.parse_utf8(&str_buf[0], len);
169169
return s;
170170
}
171171

@@ -921,7 +921,7 @@ static String get_ustring(Ref<FileAccess> f) {
921921
str_buf.resize(len);
922922
f->get_buffer((uint8_t *)&str_buf[0], len);
923923
String s;
924-
s.parse_utf8(&str_buf[0]);
924+
s.parse_utf8(&str_buf[0], len);
925925
return s;
926926
}
927927

@@ -935,7 +935,7 @@ String ResourceLoaderBinary::get_unicode_string() {
935935
}
936936
f->get_buffer((uint8_t *)&str_buf[0], len);
937937
String s;
938-
s.parse_utf8(&str_buf[0]);
938+
s.parse_utf8(&str_buf[0], len);
939939
return s;
940940
}
941941

modules/gdscript/gdscript.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ Error GDScript::load_source_code(const String &p_path) {
11431143
w[len] = 0;
11441144

11451145
String s;
1146-
if (s.parse_utf8((const char *)w) != OK) {
1146+
if (s.parse_utf8((const char *)w, len) != OK) {
11471147
ERR_FAIL_V_MSG(ERR_INVALID_DATA, "Script '" + p_path + "' contains invalid unicode (UTF-8), so it was not loaded. Please ensure that scripts are saved in valid UTF-8 unicode.");
11481148
}
11491149

modules/gdscript/gdscript_cache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ String GDScriptCache::get_source_code(const String &p_path) {
275275
source_file.write[len] = 0;
276276

277277
String source;
278-
if (source.parse_utf8((const char *)source_file.ptr()) != OK) {
278+
if (source.parse_utf8((const char *)source_file.ptr(), len) != OK) {
279279
ERR_FAIL_V_MSG("", "Script '" + p_path + "' contains invalid unicode (UTF-8), so it was not loaded. Please ensure that scripts are saved in valid UTF-8 unicode.");
280280
}
281281
return source;

modules/mono/utils/string_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Error read_all_file_utf8(const String &p_path, String &r_content) {
159159
w[len] = 0;
160160

161161
String source;
162-
if (source.parse_utf8((const char *)w) != OK) {
162+
if (source.parse_utf8((const char *)w, len) != OK) {
163163
ERR_FAIL_V(ERR_INVALID_DATA);
164164
}
165165

platform/android/export/export_plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,7 @@ String EditorExportPlatformAndroid::_parse_string(const uint8_t *p_bytes, bool p
15371537
}
15381538
str8.write[len] = 0;
15391539
String str;
1540-
str.parse_utf8((const char *)str8.ptr());
1540+
str.parse_utf8((const char *)str8.ptr(), len);
15411541
return str;
15421542
} else {
15431543
String str;

platform/windows/windows_utils.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,7 @@ Error WindowsUtils::copy_and_rename_pdb(const String &p_dll_path) {
179179
if (new_expected_buffer_size > original_path_size) {
180180
ERR_FAIL_COND_V_MSG(original_path_size < min_base_size + suffix_size, FAILED, vformat("The original PDB path size in bytes is too small: '%s'. Expected size: %d or more bytes, but available %d.", pdb_info.path, min_base_size + suffix_size, original_path_size));
181181

182-
utf8_name.resize(original_path_size - suffix_size + 1); // +1 for the \0
183-
utf8_name[utf8_name.size() - 1] = '\0';
184-
new_pdb_base_name.parse_utf8(utf8_name);
182+
new_pdb_base_name.parse_utf8(utf8_name, original_path_size - suffix_size);
185183
new_pdb_base_name[new_pdb_base_name.length() - 1] = '_'; // Restore the last '_'
186184
WARN_PRINT(vformat("The original path size of '%s' in bytes was too small to fit the new name, so it was shortened to '%s%d.pdb'.", pdb_info.path, new_pdb_base_name, max_pdb_names - 1));
187185
}

0 commit comments

Comments
 (0)