Skip to content

🐛 Fix: handle empty result values in mq_eval function#1348

Merged
harehare merged 1 commit intomainfrom
worktree-refactored-bubbling-sparkle
Feb 27, 2026
Merged

🐛 Fix: handle empty result values in mq_eval function#1348
harehare merged 1 commit intomainfrom
worktree-refactored-bubbling-sparkle

Conversation

@harehare
Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings February 27, 2026 12:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts the mq-ffi C API so that mq_eval() returns a null values pointer when the evaluation produces an empty result set, aligning the pointer value with values_len == 0 and updating the corresponding test.

Changes:

  • Return values = NULL from mq_eval() when there are no result values.
  • Update test_empty_input to expect values == NULL with values_len == 0.

Comment on lines +249 to +255
let ptr = if c_values.is_empty() {
ptr::null_mut()
} else {
let p = c_values.as_mut_ptr();
std::mem::forget(c_values); // Prevent Rust from freeing the Vec's memory
p
};
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mq_eval leaks c_values by returning as_mut_ptr() + mem::forget, but mq_free_result later reconstructs a Vec with Vec::from_raw_parts(result.values, result.values_len, result.values_len). This is UB whenever the original Vec capacity != values_len (which is common due to growth strategy), and can lead to invalid deallocation. Consider switching to a boxed slice (into_boxed_slice) and freeing with Box::from_raw(slice_from_raw_parts_mut(ptr, len)), or alternatively include the capacity in MqResult and pass it through so from_raw_parts uses the correct capacity.

Copilot uses AI. Check for mistakes.
@harehare harehare merged commit 948fccc into main Feb 27, 2026
10 checks passed
@harehare harehare deleted the worktree-refactored-bubbling-sparkle branch February 27, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants