[PR #2012] fix(rust): Remove dead code returning pointer to stack variable #2818

Closed
opened 2026-01-29 17:24:03 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/CCExtractor/ccextractor/pull/2012

State: closed
Merged: Yes


Summary

Removes unused impl FromCType<*mut PMT_entry> for *mut PMTEntry which contained a critical bug: returning a pointer to a stack-allocated value (undefined behavior).

Problem

The deleted code did this:

let mut pmt_entry = PMTEntry { ... };
Some(&mut pmt_entry as *mut PMTEntry)  // BUG: dangling pointer!

When the function returns, pmt_entry is destroyed and the pointer becomes dangling.

Why delete instead of fix?

This code was never called anywhere in the codebase:

  • The actual usage in demuxer.rs:279 uses the value-returning variant: PMTEntry::from_ctype(*buffer_ptr)
  • That call site already wraps it properly: Box::into_raw(Box::new(PMTEntry::from_ctype(...)?))

Rather than fix dead buggy code (and introduce memory ownership complexity), just delete it.

Verification

  • Build passes ✓
  • All 265 Rust tests pass ✓
  • No code references this implementation

Supersedes #1988 which attempted to fix this bug rather than delete the dead code.

🤖 Generated with Claude Code

**Original Pull Request:** https://github.com/CCExtractor/ccextractor/pull/2012 **State:** closed **Merged:** Yes --- ## Summary Removes unused `impl FromCType<*mut PMT_entry> for *mut PMTEntry` which contained a critical bug: returning a pointer to a stack-allocated value (undefined behavior). ## Problem The deleted code did this: ```rust let mut pmt_entry = PMTEntry { ... }; Some(&mut pmt_entry as *mut PMTEntry) // BUG: dangling pointer! ``` When the function returns, `pmt_entry` is destroyed and the pointer becomes dangling. ## Why delete instead of fix? This code was **never called anywhere** in the codebase: - The actual usage in `demuxer.rs:279` uses the **value-returning** variant: `PMTEntry::from_ctype(*buffer_ptr)` - That call site already wraps it properly: `Box::into_raw(Box::new(PMTEntry::from_ctype(...)?))` Rather than fix dead buggy code (and introduce memory ownership complexity), just delete it. ## Verification - Build passes ✓ - All 265 Rust tests pass ✓ - No code references this implementation ## Related Supersedes #1988 which attempted to fix this bug rather than delete the dead code. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claunia added the pull-request label 2026-01-29 17:24:03 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2818