Skip to content

Harden cc_heap removal, duplicates, and growth - #725

Merged
veelo merged 4 commits into
coin3d:masterfrom
Dikluwe:fix/cc-heap-edge-cases
Sep 28, 2026
Merged

veelo merged 4 commits into
coin3d:masterfrom
Dikluwe:fix/cc-heap-edge-cases

Conversation

@Dikluwe

@Dikluwe Dikluwe commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • repair arbitrary removal in either heap direction
  • keep pointer indices coherent when duplicate pointers are stored
  • rebuild every matching occurrence during cc_heap_update()
  • normalize zero initial capacity to one while keeping the heap empty
  • return FALSE without mutation when remove/update support is disabled
  • reject a null comparator and leave the heap unchanged if growth fails
  • keep the public heap header usable from C as well as C++

Security and compatibility

PR #624 fixed the zero-capacity growth bug that could write beyond a zero-byte allocation. This PR preserves that invariant without forbidding the public input: a requested capacity of zero now creates a valid empty heap with an internal capacity of one.

Growth is checked for overflow and uses a temporary allocation result. If allocation fails, existing storage and elements remain intact. Because cc_heap_add() has no return value, a failed growth attempt is a documented no-op.

The scheduler and SbTesselator callers were audited: they use positive initial capacities and enable removal support, so their behavior is unchanged.

Regression coverage

The tests cover:

  • zero initial capacity
  • arbitrary removal that must reheapify upward
  • duplicate pointer insertion, removal, and update
  • remove/update calls when removal support is disabled
  • null comparator rejection
  • growth from a single slot
  • compilation of Inventor/C/base/heap.h as C during configuration

Local verification

  • full Debug build and CTest: 9/9 passed
  • full Debug build with ASan and UBSan: 9/9 passed
  • public heap header verified with GCC C11, C17, and C2x
  • git diff --check passed

The branch is consolidated as three focused commits directly on the current master.

@Dikluwe
Dikluwe marked this pull request as draft September 24, 2026 03:54
@Dikluwe
Dikluwe force-pushed the fix/cc-heap-edge-cases branch from f0897df to 8023945 Compare September 24, 2026 14:01
@Dikluwe Dikluwe changed the title Fix cc_heap arbitrary removal and duplicate handling Harden cc_heap removal, duplicates, and growth Sep 24, 2026
@Dikluwe
Dikluwe marked this pull request as ready for review September 24, 2026 14:06
@Dikluwe
Dikluwe force-pushed the fix/cc-heap-edge-cases branch from 1c549e1 to cad168c Compare September 24, 2026 15:53
@veelo
veelo merged commit 7e54bba into coin3d:master Sep 28, 2026
9 checks passed
@veelo

veelo commented Sep 28, 2026

Copy link
Copy Markdown
Member

Thanks for your work, much appreciated!

@Dikluwe
Dikluwe deleted the fix/cc-heap-edge-cases branch October 4, 2026 00:27
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