]> uap-core.de Git - note.git/commitdiff
handle cstr.is_null in UiString/UiText get methods main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 26 May 2026 15:13:29 +0000 (17:13 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 26 May 2026 15:13:29 +0000 (17:13 +0200)
ui-rs/src/ui/toolkit.rs

index 25aa0c1295fd9d55c3345890f16d364b955b892e..708c22e258e693cfcc5168482f38540062860c40 100644 (file)
@@ -604,9 +604,13 @@ impl UiText {
     pub fn get(&self) -> String {
         unsafe {
             let cstr = ui_text_get(self.ptr);
-            CStr::from_ptr(cstr)
-                .to_string_lossy()
-                .into_owned()
+            if !cstr.is_null() {
+                CStr::from_ptr(cstr)
+                    .to_string_lossy()
+                    .into_owned()
+            } else {
+                "".to_owned()
+            }
         }
     }
 
@@ -701,9 +705,13 @@ impl UiString {
     pub fn get(&self) -> String {
         unsafe {
             let cstr = ui_string_get(self.ptr);
-            CStr::from_ptr(cstr)
-                .to_string_lossy()
-                .into_owned()
+            if !cstr.is_null() {
+                CStr::from_ptr(cstr)
+                    .to_string_lossy()
+                    .into_owned()
+            } else {
+                "".to_owned()
+            }
         }
     }