MCPcopy Create free account
hub / github.com/apache/paimon-rust / validate_cstr

Function validate_cstr

bindings/c/src/error.rs:91–107  ·  view source on GitHub ↗

Validate a C string pointer: checks for null and valid UTF-8. Returns `Ok(String)` on success, or `Err(*mut paimon_error)` if the pointer is null or the string contains invalid UTF-8. # Safety If `ptr` is non-null, it must point to a valid null-terminated C string.

(ptr: *const c_char, name: &str)

Source from the content-addressed store, hash-verified

89/// # Safety
90/// If `ptr` is non-null, it must point to a valid null-terminated C string.
91pub unsafe fn validate_cstr(ptr: *const c_char, name: &str) -> Result<String, *mut paimon_error> {
92 if ptr.is_null() {
93 return Err(paimon_error::new(
94 PaimonErrorCode::InvalidInput,
95 format!("null pointer passed for `{name}`"),
96 ));
97 }
98 CStr::from_ptr(ptr)
99 .to_str()
100 .map(|s| s.to_owned())
101 .map_err(|e| {
102 paimon_error::new(
103 PaimonErrorCode::InvalidInput,
104 format!("`{name}` is not valid UTF-8: {e}"),
105 )
106 })
107}
108
109/// Check that a pointer is non-null, returning an error if it is.
110pub fn check_non_null<T>(ptr: *const T, name: &str) -> Result<(), *mut paimon_error> {

Callers 5

paimon_catalog_createFunction · 0.85
paimon_identifier_newFunction · 0.85
build_leaf_predicateFunction · 0.85

Calls 1

is_nullMethod · 0.80

Tested by

no test coverage detected