Skip to content

Commit

Permalink
Allow null Vec<PluginMetadata> pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortham committed Jun 23, 2024
1 parent 3e760a5 commit 37babed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ffi/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,15 @@ pub unsafe extern "C" fn esp_plugin_resolve_record_ids(
plugins_metadata: *mut Vec<PluginMetadata>,
) -> u32 {
panic::catch_unwind(|| {
if plugin_ptr.is_null() || plugins_metadata.is_null() {
if plugin_ptr.is_null() {
error(ESP_ERROR_NULL_POINTER, "Null pointer passed")
} else {
let plugin = &mut *plugin_ptr;
let plugins_metadata = &*plugins_metadata;
let plugins_metadata = if plugins_metadata.is_null() {
&[]
} else {
(&*plugins_metadata).as_slice()
};

match plugin.resolve_record_ids(plugins_metadata) {
Ok(_) => ESP_OK,
Expand Down
3 changes: 3 additions & 0 deletions ffi/tests/ffi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ void test_esp_plugin_resolve_record_ids() {
return_code = esp_plugin_parse(plugin, true);
assert(return_code == ESP_OK);

esp_plugin_resolve_record_ids(plugin, nullptr);
assert(return_code == ESP_OK);

Vec_PluginMetadata * plugins_metadata;
return_code = esp_get_plugins_metadata(&plugin, 1, &plugins_metadata);
assert(return_code == ESP_OK);
Expand Down

0 comments on commit 37babed

Please sign in to comment.