File tree 2 files changed +18
-0
lines changed
2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,11 @@ impl GodotString {
55
55
let len = interface_fn ! ( string_to_utf32_chars) ( s, std:: ptr:: null_mut ( ) , 0 ) ;
56
56
let ptr = interface_fn ! ( string_operator_index_const) ( s, 0 ) ;
57
57
58
+ // Even when len == 0, from_raw_parts requires ptr != 0
59
+ if ptr. is_null ( ) {
60
+ return & [ ] ;
61
+ }
62
+
58
63
validate_unicode_scalar_sequence ( std:: slice:: from_raw_parts ( ptr, len as usize ) )
59
64
. expect ( "GodotString::chars_checked: string contains invalid unicode scalar values" )
60
65
}
@@ -71,6 +76,11 @@ impl GodotString {
71
76
let s = self . string_sys ( ) ;
72
77
let len = interface_fn ! ( string_to_utf32_chars) ( s, std:: ptr:: null_mut ( ) , 0 ) ;
73
78
let ptr = interface_fn ! ( string_operator_index_const) ( s, 0 ) ;
79
+
80
+ // Even when len == 0, from_raw_parts requires ptr != 0
81
+ if ptr. is_null ( ) {
82
+ return & [ ] ;
83
+ }
74
84
std:: slice:: from_raw_parts ( ptr as * const char , len as usize )
75
85
}
76
86
}
Original file line number Diff line number Diff line change @@ -56,6 +56,14 @@ fn string_clone() {
56
56
assert_eq ! ( first, cloned) ;
57
57
}
58
58
59
+ #[ itest]
60
+ fn empty_string_chars ( ) {
61
+ // Tests regression from #228: Null pointer passed to slice::from_raw_parts
62
+ let s = GodotString :: new ( ) ;
63
+ assert_eq ! ( s. chars_checked( ) , & [ ] ) ;
64
+ assert_eq ! ( unsafe { s. chars_unchecked( ) } , & [ ] ) ;
65
+ }
66
+
59
67
// ----------------------------------------------------------------------------------------------------------------------------------------------
60
68
61
69
#[ itest]
You can’t perform that action at this time.
0 commit comments